19

I recently found that packets are encapsulated within ethernet frames. Packets use IP addresses, frames use MAC addresses.

Why aren't IP addresses used in ethernet frames for routing? I understand that when trying to access a basic website, the computer goes to a DNS to find the IP address relevant to the user-entered domain name. How do computers find the correct MAC address?

Really, how are MAC addresses used in routing internet traffic?

Thanks

6 Answers 6

17

IP packets aren't always encapsulated in Ethernet frames. There are other physical media such as ISDN, etc. When packets are routed, IP addresses are used to determine the next hop and the physical address is used to physically identify the interface serving as the next hop. Only the former (determining next-hop) is usually called routing.

To answer your second part, MAC addresses are discovered through ARP (Address Resolution Protocol) in IPv4 & ND6 (Neighbor Discovery) in IPv6.

Update: The destination IP address in the IP header is the final destination. In the process of routing (at each hop), you get the next hop's IP address to (eventually) reach the final destination from the routing table (this could be a default gateway's IP address). To send the packet to the next hop, you need its MAC address. While hopping through intermediate links, the IP address in the IP header don't change - only the MAC addresses change.

3
  • 4
    I think I understand now. The IP address is the final destination of the machine or network the data needs to go to, which helps the routing software find the next MAC address. The MAC address is the address of the next 'hop' that needs to be done, it is the address of the next step in the chain and changes each time it gets to the next destination. So if I send a packet to facebook, the IP address will be a facebook server IP and the MAC will be my router, or the next step after the router. Each step finds the next MAC to send to. Is this correct?
    – BenAdamson
    May 29, 2014 at 14:16
  • 1
    See update to the answer, too long to comment here :)
    – jman
    May 29, 2014 at 16:12
  • why do i need next hop's IP address and next hop's MAC address both to send packet to the next hop? wouldn't next hop's IP address be sufficient to send packet to next hop? May 17, 2022 at 12:25
5

Bit late but still here is my answer :) ... To send data you need two address, the MAC address and the IP address. Basically the sending host will ARP for a MAC address, this occurs when the local host doesn't know the MAC address of the host it has an IP address for or it will ARP for the default gateway MAC address (if it doesn't already know it) if the IP address in on a different subnet/ network. Once it obtains a MAC address the IP packet is encapsulated in a L2 frame and sent across the media. If the IP packet is meant for a host on a different subnet/ network, it will be sent to the default gateway, this router will de-encapsulate the L2 frame (remove and discard it) check the IP address and will forward it. For the router to do this it needs a MAC address to send it over the media, It will look up the next hop in it's routing table, encapsulate the IP packet with the same source and destination IP address that was sent from the original host into a new L2 frame. This time the MAC address for the source address will be that of the forwarding interface of the router, and the receiving interface of the next hop will be the destination MAC address. This will continue from hop to hop until it reaches the final host, each time the MAC addresses will change, but the original IP address will remain the same.

1
  • 1
    Could u pls clarify what we achieve by updating the src mac address hop to hop ? Jan 4, 2017 at 17:50
2

Here's the key point -- there can be more types of packets than INTERNET traffic. You could be using IPX, which is non-routable. How do clients identify each other? By the MAC address.

Routing != Addressing, which is really where the MAC comes into play.

In order to be routed, the OSI model adds a layer to allow for path discovery to the next gateway. This layer is responsible for routing, but knows nothing about the MAC address.

As a side note, at the hardware level, MAC addresses ARE used by switches, but not for routing. From How Stuff Works:

The switch gets the first packet of data from Node A. It reads the MAC address and saves it to the lookup table for Segment A. The switch now knows where to find Node A anytime a packet is addressed to it. This process is called learning.

In this way, a switch can make sure that traffic is only outputted to the correct port. This isn't accomplishing routing so much as reducing network congestion. Only broadcasts and traffic destined specifically for that MAC address should be sent out the port.

0

Recently I have been thinking about the same and came upon this question. Here is my answer to this question. Actually MAC address is needed for correctly sending the packet to right destination. This is specially true when packet is needed to sent over a VLAN. There can be multiple switches/routes connected on that VLAN over multiple physical interfaces. However IP Routing is unaware of these physical interface. It only knows about the logical connectivity. For example, route 10.10.10.0/24 is reachable via VE/VIF0.10(logical VLAN interface) and/or nexthop neighbor is 20.20.20.1. There could be multiple interfaces under VLAN 10. Then to which interface packet is sent out? This is where ARP comes in the picture. ARP helps to discover the MAC address associated with the next-hop IP address. When switch/router learns the nexthop MAC. along with that it learns the physical interface also via which that MAC is reachable. Hence while routing packet, firstly MAC corresponding to the destination IP is searched and then the physical interface associated with that MAC is searched. Finally packet is sent out via that physical interface. The MAC corresponding to that destination IP is used as destination MAC. In absence of this, routed packets will always be flooded in the outgoing VLAN.

Hope this helps.

Thanks.

0

The interaction between IP addresses and MAC addresses occurs in the following ways:

Address Resolution Protocol (ARP): When a device wants to communicate with another device on the same local network, it uses the ARP protocol to resolve the MAC address associated with a specific IP address. The requesting device broadcasts an ARP request packet containing the target IP address. The device with the corresponding IP address responds with an ARP reply packet, providing its MAC address. This allows the requesting device to learn the MAC address it needs to communicate with the target device on the local network.

Routing: When a device wants to send data to a device on a different network segment, it uses IP routing. The device encapsulates the data into an IP packet with the source and destination IP addresses. The source MAC address is the MAC address of the sender's NIC. The destination MAC address is determined based on the routing process. If the destination IP address is on a different network segment, the sender's NIC uses the MAC address of the default gateway (router) to forward the packet. The router examines the destination IP address and determines the appropriate outgoing interface and the MAC address of the next hop to forward the packet.

-1

Answer: MAC addresses are not used in the process of routing of a packet.

  • segment -> transport layer (TCP ports)
  • packets -> network layer (IP addresses)
  • frame -> data link layer (MAC addresses)
  • bits -> physical layer (electric/optical signals)

Create your own packet/segment visit http://wirefloss.com/wireit/

There are 2 models (TCP/IP and ISO/OSI)

In detail: Your app has some data. This is encapsulated by mentioned layers. Encapsulation means that a header with fields is added at each layer. If your data never leave the local network the MAC address will be the same. Once your data needs to be delivered outside your network the frame header is stripped by router and is replaced by router fields.

UPDATE 2021: Some people seems never heard of ISO OSI model and put this answer as incorrect.

ISOOIS vs TCP

3
  • 2
    segment is transport layer, packets are network layer, frame is data link
    – 4pie0
    Jul 12, 2016 at 22:02
  • Your comment is totally wrong if you do not mention which model you are referring. Check ISO/OSI model. If you refer TCP/IP you are correct.
    – Marek H
    Jul 17, 2016 at 9:29
  • I do not think this is true. The same naming convention applies.
    – 4pie0
    Jul 17, 2016 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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