Ever wondered how different layers of network work together to send a message. Lets understand some basic terms before getting into details.
- A Default Gateway serves as an access point or IP router that a networked computer uses to send information to a computer in another network or the internet.
- Address Resolution Protocol (ARP) request is a protocol which converts IP address into MAC address.
- A Routing tables is a set of rules, often viewed in table format, that is used to determine where data packets traveling over an Internet Protocol (IP) network will be directed.
Generally a host or a computer has all layers (from application layer to physical layer ) and a router has network, data link layer and a physical layer.
Now lets understand the working of different layers with the help of an example.
Suppose you want to send a message to an application on host2 (assume it is present in different network).
Let the IP and MAC address of host1 be I1 , M1 and IP and MAC address of host2 be I2 , M2. Suppose the default gateway of host1 be router1(IP address be IR1, Mac address be MR1) and the default gateway of host2 be router2 (IP address be IR2, Mac address be MR2).
Suppose the application layer wants to send a message M to host2. The application layer of host1 gives it to transport layer of host1. Transport layer will add header to the message M which contains the port number of host1, host2(x,y). Therefore now the message will be (M,x,y) and this will be given to network layer of host1. Network layer also adds an header to the message which contains the Ip address of host1 and host2.
Now the message will be (M,x,y,I1,I2) and it will be given to DataLink layer. Data link layer also adds an header for the message before giving it to the physical layer. Since the host2 is not present in the same network it will put the mac address of host1 and mac address of default gateway (it will know the mac address by sending an ARP request). Now the message will be (M,x,y,I1,I2,M1,MR1) and this will be given to physical layer. Physical layer converts the given message to bits and sends it the router1.
The physical layer will convert the bits into message and will inform the datalink layer that this packet should be processed after seeing the Mac address of router1. After seeing the packet the datalink layer of router1 will send an acknowledgment to datalink layer host1 and will remove the header information added at DLL of host1 before giving it to Network layer of router1. The message that network layer gets is (M,x,y,I1,I2).
Network layer sees the destination Ip address and sice the destination is not present in its network it will decide it forward it router2. Network layer of router1 decides it after seeing the routing tables at router1 and will decide it.Now the DLL of router adds header to the message. This time the source mac address will be MR1 and destination MAC address will be MR2 (using Arp it finds out). In this way the receiver only knows the Ip address of source and it will never know the mac address of the source. Now the message will be (M,x,y,I1,I2,MR1,MR2) and it will be given to physical layer. The physical layer converts it to bits and sends it router2.
The physical layer will convert the bits into message and will inform the DLL of router2.Now the DLL of router2 will send an acknowledgment to DLL of router1 after seeing the message. DLL of router2 will remove the MAC address and give it to network layer.
Now the network layer finds out that the host2 is in the network to which the router2 is connected so it will send the message to host2. Network layer finds out that host2 is in the same network after seeing the routing tables present at the router2.N ow the DLL will add the header information with mac address of router2 (sender) and M2(destination) (it finds out using ARP request). Now the message will be (M,x,y,I1,I2,MR2,M2) and will be given to physical layer which converts it to bits and sends it host2.
The physical layer will convert it into bits and will give the message to DLL. DLL sends an acknowledgment to DLL of router2 and removes the MAC address on the message, which will be given to NL. Now the network layer will remove the IP address and gives it Transport layer.
Now the transport layer will send an acknowledgment to Transport Layer of host1 (in case of TCP since it has the IP address of host1. The message will be (M,y,x,I2,I1)) and removes the port number and gives the message to the process(or application) present at y.
- Since Transport layer is responsible for end to end connectivity , transport layer of host2 sends an acknowledgment to transport layer of host1.
- DataLink layer is responsible for hop to hop connectivity , each time a router/host receives a packet acknowledgment is sent to respective data link layers.
- Network layer takes care of bit level error and transport layer takes care of packet errors.
- Routers MAC address is temporary because ISP generally changes the NIC (Network Interface Card) which contains the MAC address. So default gateway IP address is shared to hosts and other routers and not MAC address.
This is how the message from one host is delivered to another host on different network.
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Basic Network Attacks in Computer Network
- Layers of OSI Model
- Difference between Storage Area Network (SAN) and Network Attached Storage (NAS)
- Differences between Wireless Adhoc Network and Wireless Sensor Network
- Difference between Next Generation Network and Traditional Network
- Difference between Software Defined Network and Traditional Network
- Packet flow in different Network
- Different Ways to Prepare an IT Network for IoT
- Computer Network | Leaky bucket algorithm
- HMAC Algorithm in Computer Network
- Introduction of Firewall in Computer Network
- Circuit Switching in Computer Network
- Packet Switching and Delays in Computer Network
- Routing v/s Routed Protocols in Computer Network
- Collision Domain and Broadcast Domain in Computer Network
- Difference between Unicast, Broadcast and Multicast in Computer Network
- Introduction of MAC Address in Computer Network
- Unicode in Computer Network
- Types of Server Virtualization in Computer Network
- Hamming Code in Computer Network
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.