If application data needs to be sent to IP address xx.xx.xx.xx, how does it work in underneath network?
This is to illustrate the communication between two separate machines which don't have a direct physical connection.
Application data is generated and passed to layer 3 (network layer) which wrapps up the data with the destination IP address. Then hands to layer 2 (link layer) which has a lookup table of IP addresses and their corresponding MAC addresses in the local network. Layer 2 looks at the IP address and try to resolve the IP address. If the IP address is in the table, it will wrap the layer 3 envelope in a layer 2 envelop with the MAC address in the header and then pass to physical layer to do the data communication.
Alternatively, if IP address is not in the lookup table, it will have the MAC address of default gateway (i.e. router) and forward data to the router The routers notices that the envelope has its own MAC address. It opens up the layer 2 envelope, look at the IP address and works out where to send the message, which probably forward to the ISP router. These steps repeat untill data is sent to the destination.
- MAC address will not be routed to router. It is only used for the communication inside the local physical network (LAN)
- It is in layer 2 that MAC address starts playing the game.
- IP addresses cover the whole internet and routers use them to figure out where to send the data