Network Engineering Stack Exchange is a question and answer site for network engineers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I know that MAC addresses are used in networks for several things, e.g. static fixed IP addresses assigned by DHCP servers or for Wireless access points. But why is it necessary in the Internet?

Let's say I send a packet to someone not on my local network, e.g. www.example.com using a ICMP echo signal. The ICMP echo doesn't contain any application layer or transport layer. DNS will find out that the IP address of www.example.com is 93.184.216.34.

Well, but how does it find out it's MAC address needed for 802.11 data link layer? No machine on my local network knows it. Why is it even necessary to add the MAC address? The IP address will already uniquely identify it, won't it? And how do routers look up the IP address, if it is hidden beneath the data link layer?

EDIT:

I learned that the 802.11 header as well as the 802.3 header contains a field for Destination MAC addresses. I know that my machine contains an ARP table which contains the MAC address of my router. But what MAC address will be written inside that field between my router and the destination router?

share|improve this question

marked as duplicate by Ron Trunk, Ron Maupin, Craig Constantine Feb 5 at 16:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
You could ask the question the other way: What use are IP addresses if I already have the MAC address? – Ron Trunk Feb 4 at 18:55
    
So they fulfill the same purpose? There is DNS for IP addresses, but nothing similiar for MAC addresses. – hgiesel Feb 4 at 18:56
    
That was rhetorical question. – Ron Trunk Feb 4 at 18:57
    
The answer answer to your edit is the destination MAC will be the address of the next hop device. – Ron Trunk Feb 4 at 23:11
1  
Never used the chat, but I'd be willing too – hgiesel Feb 5 at 0:15
up vote 13 down vote accepted

Well, but how does it find out it's [www.example.com's] MAC address needed for 802.11 data link layer?

Your computer doesn't, nor does it need to do so. Since the MAC address is only used within the same L2 network, when you are sending traffic to a different L3 network, all it needs to know is that www.example.com is on a different L3 network and how to get to that L3 network.

Generally this is the default gateway for most devices, and as you point out, your computer already has the information for your router in your ARP table. The router will adjust the L2 information before it passes the traffic on to the next L3 device.

Why is it even necessary to add the MAC address? The IP address will already uniquely identify it, won't it?

No, IP address are not necessarily unique. They must be unique on the local network, but they can be re-used. This is one of the reasons that NAT exists.

Further, Ethernet is only one L2 protocol. IP is designed to work without concern for the underlying protocol, so you could replace Ethernet with something else (like Token Ring or Frame Relay) or you could create your own L2 protocol if you wanted. IP wouldn't care or be bothered by the change.

And how do routers look up the IP adress, if it is hidden beneath the data link layer? I don't really get it...

The L3 header is not "hidden" by the L2 header. The L2 header doesn't change the content that becomes the L2 payload, it is simply pre-pended or added before the L3 header. Many devices will strip off the L2 header before L3 processing, but even if this isn't always the case it doesn't obscure the meaning of the rest of the message.

Think of it this way, let's say I send you a message that said, "How are you today?" This passes through a translator who changes it to, "Hello, how are you today?" Can you still understand my original message even though a new "header" was added to it? And that additional header may be removed before final delivery to you.

But what MAC address will be written inside that field between my router and the destination router?

When your router sends the traffic to the next router (assuming they are using Ethernet), it will use the MAC address of it's interface as the source MAC address and the MAC address of the next router's interface as the destination address.

There are probably dozens of questions on this site that focus on different aspects of these questions. Please feel free to use the search function to find them. Here are a few to get you started:

And since you touched on 802.11:

share|improve this answer
1  
"The L3 header is not "hidden" by the L2 header. The L2 header doesn't change the content that becomes the L2 payload" - this is also called encapsulation, if I remember correctly. It works like a matryoshka doll. The IP packet (or generally OSI Layer 3 PDU) is encapsulated into a frame, on the other side, the frame is stripped away, leaving the intact IP packet, and so on. – ROAL Feb 5 at 8:07
    
@ROAL, yes, Ethernet does encapsulate as there is a trailer as well. However, some forms of encapsulation can change the content of the payload. Also, while the analogy to the matryoshka doll does work, in this context it can result in confusion for the OP as with the doll the inner content is "hidden." – YLearn Feb 5 at 9:11

MAC addresses are layer 2 addresses. They are used to address devices at the hardware level. Ethernet, for example, is a layer 2 protocol, and it uses MAC addresses to send data to devices.

Ultimately, you need to address physical devices on the Internet. That's where layer 2 addresses (MAC addresses) come into play.

share|improve this answer

Like an IP address is used at the IP level (layer 3), a MAC address is used at the MAC level (layer 2), i.e. Ethernet, Wi-Fi, etc.

When you send a packet to a host, your computer does the following:

  • It checks if the host is on one of the directly connected networks (your local LAN, in general).

  • If it is, it uses ARP to map the IP to a MAC address (either via the ARP cache, or by broadcasting an ARP request on the network). This way, it'll find the destination MAC address to put in the frame.

  • If it isn't, it'll use the routing table to find where to send the packet (usually your default gateway, i.e. your router). Likewise, it'll use ARP to find the MAC address of said gateway (in most cases this will be in cache). It'll then use this as the destination MAC address.

The source MAC address will be that of your computer.

If the packet is delivered to a host on your local network, that's the end of the story. If it's delivered to a router, then the process starts again, with new source and destination MAC addresses on each "hop" that requires any (point-to-point links don't, obviously).

MAC addresses are needed for Layer 2 switches to be able to correctly forward frames to the right ports without having to know anything about Layer 3 (IP) addresses or anything like that. This is what makes switches designed decades ago able to correctly forward IPv6 frames, or any other Layer 3 protocol you might come up with, as long as it's correctly framed with appropriate MAC addresses.

share|improve this answer

I think the @Ron Trunk´s answer it is great for you, and, for your notation, everytime that a packet arrives to a router and is routing by some interfaces, in that moment, the source mac address field change by the owner mac address of that port, allowing fast connectivity by l2. In fact, on the moment that the packet arrives to it destination, it comes with the source mac address of the gateway of the destination network.

You can look in a easy and safe way that whe are talking about if you simulate with packet tracert, gns3,... and capture the traffic and compare the mac address.

Mac address are for l2 connectivity like ip address are for l3 connectivity

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.