How does Netwoking work?
From Initq
Have you ever thought when you type in the url on your address bar and hit enter, what really happens? How does that url get translated and how does it know where to go and fetch the information you requested? Well, we are going to explain how it all works in a very simple way.
We have to understand the OSI model to understand how packets travel. So, we will use the layers to explain how information travels.
Contents |
Network Layer (IP)
I am on initq.com and want to look up a webpage on deinkampf.com so i type deinkampf.com in my browsers address bar.
Step 1 (translate name to ip)
My machine initq.com first has to translate the requested name deinkampf.com into an ip address. It does that by searching locally first in the local hosts file and if not found there then it sends a request to the DNS server. Normally when you set up networking on your machine you always put one or two ip addresses for DNS servers given by your ISP or your admin in a work environment.
The DNS ip is put in the packet and it determined by your own computer if that ip is on your network or external to your network. Lets take the latter and pursue that. So if the ip of the DNS is external to your network then your computer also knows what its gateway is since that is also set on your networking setup.
Data Link Layer (MAC)
The protocol on your machine called arp is invoked to get the MAC address of your gateway. Your computer will send out a broadcast and hit the gateway computer. The gateway computer will recognize its ip and respond with its MAC address back to initq.com. The reason we need the MAC address is because the Data link layer uses MAC address and not ip address. Now that we have the destination ip of the DNS server and enclosed the packet with the data link layer MAC address of our gateway, we are ready to send the packet.
Step 2 (Gateway gets the packet)
The gateway gets the packet and opens the packet to find out on the network layer that the ip is not meant for itself but checks its routing table for the closest match to the destination IP (DNS server) to figure out which interface to use. Routers may have more than two interfaces connected to it, some have many so the routing table will tell the router which interface to use in order to get the packet to its destination and have leaset amount of hops. Once the routing table decides which interface to forward the packet to, the MAC address of the destination will be needed again. The proper protocol will be used here to get the MAC address of the next hop, it could be arp but rather that will depend on the protocol used on that router such as frame relay, etc. Once the MAC address is retrieved, our original packet it enclosed in the new MAC address and send on to the next hop.
Step 3 (Keep Hopping until)
The hopping process keeps going from router to router until it reaches the network where your DNS server resides. It opens the packets and sees that you wanted the ip address of deinkampf.com, it searches it's databases and gets the ip for deinkampf.com, closes the packet and sends it back to initq.com.
Step 4 (Getting the packet back from DNS)
The DNS server now sends the packet back to initq.com and again it goes through hops and hops and reaches initq.com.
Step 5 (Send request to deinkampf.com)
Now that you have the ip address of deinkampf.com, your computer figures out that deinkampf.com is not on its network so it encapsulates the packet with the MAC address of the gateway and send the packet to it. Your arp caches the MAC address for a bit so the MAC address of the gateway was left over from the request we just made a few seconds ago.
Step 6 (Gateway gets the request again)
The gateway gets a new request now, it opens the packet and looks at the ip address on deinkampf.com. It looks at its routing table and tries to determine which interface to send the pack to. Once it decides it encapsulates the packet with the destinations MAC address and send it off to the next hop which will be another router.
Network Layer (IP)
Step 7 (Packet arrived at deinkampf.com)
After a few hops the packet reaches a router to which deinkampf.com is directly attached to. That router encapsulates the packet with deinkampf.com's MAC address and send the packet to it. Deinkampf.com opens the packet and see that the ip address matches its own on the Network layer.
Transport Layer (TCP)
then goes down the TCP layers to find out that it is a SYN request.