9

I have to teach my sixth form about MAC Addresses and IP Addresses in a few weeks time and there are some areas I am unclear on which I am hoping some of you will be able to clarify for me. I have enough to get them through the syllabus, but I like to have more knowledge than the spec so that I can explain how things work in more meaningful way.

So as I understand it the following happens when a device on a LAN sends a packet/frame to a device on another separate LAN via the internet.

A packet is created at the sending end with the destination and sending IP

First question: Is the destination IP actually the IP of the gateway for the receiving device’s LAN

This is then turned into a frame which will go to the gateway for the LAN - this happens at the data link layer and the frame has a MAC sending and destination address added

First question: The destination MAC address - is this the final destination or the destination of the gateway?

The packet/frame is then sent onto the internet and routed (using the IP address) to the next hop towards the final destination

Second question: At each hop, does the data link layer change the destination MAC address in the frame to the MAC address of the next hop?

The packet/frame is routed to the destination address (which is the gateway )

Third question: Once the frame/packet reaches the gateway of the receiving LAN is the destination MAC address in the frame used by a switch to ensure it ends up at the correct device? This obviously assumes that the destination MAC address is not amended by the routers as the frame/packet traverses the internet - if it is amended then once the receiving gateway receives the frame/packet, how does it know where to send it?

3 Answers 3

6

MAC addresses are layer-2 addresses in the frame header. The layer-2 frame encapsulates the layer-3 IP packet. The layer-2 frame is stripped off at a layer-2/3 boundary (e.g. a router). If the layer-3 packet needs to be forwarded through another layer-2 domain, a new layer-2 frame is created using MAC addresses in the new layer-2 domain to encapsulate the layer-3 packet.

Conceptually:

To the router:

<L2 frame><L3 packet><L4 segment>PAYLOAD DATA</L4 segment></L3 packet></L2 frame>

In the router:

<L3 packet><L4 segment>PAYLOAD DATA</L4 segment></L3 packet>

From the router:

<New L2 frame><L3 packet><L4 segment>PAYLOAD DATA</L4 segment></L3 packet></New L2 frame>

The original layer-2 frame will contain the source MAC address of the sender, and the destination MAC address of the router's interface in that layer-2 domain.

The new layer-2 frame will contain the source MAC address of the router's interface in the new layer-2 domain, and the destination MAC address of the next hop in the new layer-2 domain.

The layer-3 packet will contain the layer-3 source IP address of the originator of the packet, and the layer-3 destination address of the final layer-3 destination.

Layer-2 MAC addresses are removed at each layer2/3 boundary along the routes to be replaced with the MAC addresses of the new source and destination, but the layer-3 IP addresses stay the same along the path (with certain exceptions like NAT).

4

Just wanted to add this animation to complement the accepted answer.

mac/ip

(This awesome GIF is from here.)

1

First question: The destination MAC address - is this the final destination or the destination of the gateway?

The MAC addresses are used in the layer 2 of the frame, and the layer 2 define the local network. So, the destination MAC address is the address of your gateway if the final target is not on the same LAN.

Second question: At each hop, does the data link layer change the destination MAC address in the frame to the MAC address of the next hop?

Yes, or the MAC address of the final target if it is on the same LAN.

Third question: Once the frame/packet reaches the gateway of the receiving LAN is the destination MAC address in the frame used by a switch to ensure it ends up at the correct device? This obviously assumes that the destination MAC address is not amended by the routers as the frame/packet traverses the internet - if it is amended then once the receiving gateway receives the frame/packet, how does it know where to send it?

With the IP address of the final target and his routes (LAN address and masks), the router can deduct if the target of the packet is on the same LAN or not. If the IP address is in the range of the LAN IP address and the mask, it knows the final target is in a LAN the router is connected.

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.