Why IP (at Layer 3) needs MAC address (a Layer 2 information) ?
GeneralThis forum is for non-technical general discussion which can include both Linux and non-Linux topics. Have fun!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Why IP (at Layer 3) needs MAC address (a Layer 2 information) ?
Hi there,
I am studying OSI and TCP/IP model. And I have a problem:
MAC addressing (physical addressing) is used at Layer 2.
IP addressing (logical addressing is used at Layer 3.
IP and ARP protocols both work at Layer 3. Then why does IP needs destination's MAC address that is only a Layer 2 information? IP uses the service of ARP protocol to find Physical address given a host's Logical Address. But why IP needs MAC address ?
You can't send a frame to an IP address on an ethernet/802.3 or 802.11 network. Or really any layer 2 network, come to think of it. You can, however, send a frame from one MAC address to another.
In other words, to send an IP packet from one node to another on a layer 2 network, the IP stack first needs to locate the corresponding MAC address for the destination IP. It uses ARP to do this. The IP packet is then encapsulated in a header appropriate for the layer 2 network in question (say, ethernet), and sent as one or more frames across that network.
Thanks Ser Olmy but MAC address, as you said yourself, is used with frames at layer 2. In TCP/IP or OSI model, I studied that layer 2 is responsible for framing and physical addressing. So finding or mapping fromIP to MAC address should also done by layer 2 and not by layer 3. This is the main confusion that is still not clear.
The concept is that each layer provides services to the layer above. For instance, layer 2 is given a chunk of data by a layer 3 protocol, and is told "send this to layer 2 address X".
In order to do the above, the layer 3 protocol has to include protocols that perform layer 3 to layer 2 mapping. For IPv4, that protocol is ARP. It may sound like layer 3 needs to have at least a rudimentary understanding of the underlying layer 2 protocol in order to support it, and that's precicely how it works.
The opposite is not true. You may not tell layer 2 "send this chunk of data to layer 3 address X", as layer 2 cannot resolve the mapping between layer 3 and layer 2. If that was the responsibility of layer 2, it would need knowledge of every possible layer 3 protocol in existence.
IP only needs MAC addresses when being transmitted over a L2 technology that uses MAC addresses. If you Run IP over ATM there is not a MAC address to be seen. Send IP over PPP and again no MAC address. These technologies use their own addressing schemes and in each case IP needs to map the next-hop IP address to a L2 address to be able to transmit the IP packet (in a L2 frame suitable for the L2 technology. There is normally a variant of ARP which does this.
Thanks. Does that mean that if an IP packet needs to pass through an L2 technology then MAC is required and not required otherwise?
If a packet doesn't have to pass through layer 2, then there's no need to perform a layer 3 to layer 2 mapping.
For instance, consider an application communicating with a server process, both running on the same physical system but bound to different IP addresses. The packets will go from the application down to layer 3, get routed directly to the other IP address, and then go up the chain to layer 7 and the server process.
As long as the packet has to traverse some form of physical network technology, layer 2 will be involved. This may or may not involve MAC addresses (as baldy3105 pointed out), depending on the network technology in question. (Nitpick: The virtual interfaces created by PPP actually do have MAC addresses.)
Thanks. Does that mean that if an IP packet needs to pass through an L2 technology then MAC is required and not required otherwise?
Best Regards.
Nearly, remember only Ethernet, Token Ring, and Arcnet (off the top of my head) use MAC addresses. Frame Relay can be considered a L2 technology, as can ATM, or PPP or X25. None of these understands MAC addresses. So its more correct to say that "if an IP packet needs to pass through an L2 technology then a L2 address is required". If said L2 is Ethernet then that L2 address is indeed a MAC.
Code:
L3 IP <----------------------------------------IP----------------------------------------------------------> IP
L2 [host]<--ethernet-->[router]<--frame relay-->[router]<---ATM-->[router]<---PPP--->[router]<---token-ring--->[host]
In this quick illustration you can see how IP maps to the appropriate L2 as it hops along its path from source to destination. Only the ends , ethernet and token ring, require MAC addresses.
Its important to note that the MACs used at the Token Ring end are NOT the same as were used over the originating Ethernet, those got left behind at the first router.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.