Let's take a look as we use a simple PING request from one computer to another computer. Two computers are on two different networks separated by a
router. Each computer is connected to a
switch in its respective network. The example below will assume that ARP has already done its job, and the ARP tables on all devices have been populated. The purpose of this example is to simply show how the IP and MAC addresses appear in the packets as the PING request and replies travel across the network.
The Network:
PC0 in the first network has an IP address of
192.168.1.100, and a MAC address of 09D4.
The default gateway for PC0 is 192.168.1.1, with a MAC
address of 7B9B.
Laptop2 in the second network has an IP
address of 10.10.1.102 and a MAC address of 0BD6. The default gateway for Laptop2
is 10.10.1.1 with a MAC address of 295D.
This article will explain how the destination and source IP address and MAC change as the PING packet travels from one computer to the other and then returns with the PING reply. Again - the example below will assume that ARP has already done its job at each step, and the ARP tables on all devices have been correctly populated.
Note:
The MAC addresses in this example were truncated to the last 4 hexadecimal
characters (16 bits) for brevity.
Using the network diagram above, let's go through the steps
of how the destination and source IP addresses and MAC addresses change as a
PING packet travels from PC0 to Laptop2 and then returns to PC0 with the PING
reply:
The Packet Journey:
PING Request
Path:
From PC0 to LAN1 Switch:
· Source IP address: 192.168.1.100 (PC0's IP address)
· Source MAC address: 09D4 (PC0's MAC address)
· Destination IP address: 10.10.1.102 (IP address of Laptop2)
· Destination MAC address: Since the destination IP address is in a different network, PC0 will send the packet to its default gateway 192.168.1.1 (MAC Address 7B9B), which is the router.
From LAN1 Switch to Router:
· Source IP address: 192.168.1.100 (unchanged)
· Source MAC address: 09D4 (unchanged)
· Destination IP address: 10.10.1.102 (unchanged)
· Destination MAC address: 7B9B (MAC address of the router's LAN1 interface).
From Router to LAN2 Switch:
· Source IP address: 192.168.1.100 (unchanged)
· Source MAC address: 295D (MAC address of the router's LAN2 interface)
· Destination IP address: 10.10.1.102 (unchanged)
· Destination MAC address: Since the destination IP address is within the same network as Laptop2, the router will perform an ARP request to find the MAC address corresponding to the IP address of Laptop2. The ARP reply will return a MAC address of 0BD6.
From LAN2 Switch to Laptop2:
· Source IP address: 192.168.1.100 (unchanged)
· Source MAC address: 295D (MAC address of the router's LAN2 interface) (unchanged)
· Destination IP address: 10.10.1.102 (unchanged)
· Destination MAC address: 0BD6 (MAC address of Laptop2).
· The PING request packet has now reached Laptop2. Laptop2 processes the packet and generates a reply.
PING
Reply Path:
From Laptop2 to LAN2 Switch:
· Source IP address: 10.10.1.102 (Laptop2's IP address)
· Source MAC address: 0BD6 (Laptop2's MAC address)
· Destination IP address: 192.168.1.100 (IP address of PC0)
· Destination MAC address: Since the destination IP address is in a different network, Laptop2 will send the packet to its default gateway, 10.10.1.1 (MAC Address 295D) which is the router.
From LAN2 Switch to Router:
· Source IP address: 10.10.1.102 (unchanged)
· Source MAC address: 0BD6 (Laptop2's MAC address) (unchanged)
· Destination IP address: 192.168.1.100 (unchanged)
· Destination MAC address: 295D (MAC address of the router's LAN2 interface).
From Router to LAN1 Switch:
· Source IP address: 10.10.1.102 (unchanged)
· Source MAC address: 7B9B (MAC address of the router's LAN1 interface)
· Destination IP address: 192.168.1.100 (unchanged)
· Destination MAC address: Since the destination IP address is within the same network as PC0, the router will perform an ARP request to find the MAC address corresponding to the IP address of PC0. The ARP reply will return a MAC address of 09D4.
From LAN1 Switch to PC0:
· Source IP address: 10.10.1.102 (unchanged)
· Source MAC address: 7B9B (MAC address of the router's LAN1 interface) (unchanged)
· Destination IP address: 192.168.1.100 (unchanged)
· Destination MAC address: 09D4 (MAC address of PC0).
· The PING reply packet has now reached PC0.
In summary, as the PING packet travels from PC0 to Laptop2
and then back to PC0, the source and destination IP addresses remain the same,
but the source and destination MAC addresses change at each hop as the packet
passes through switches and the router.
Memory Aid: Layer 3 (IP Address) is end-to-end and stays the same in the packet throughout the journey. Layer 2 (MAC Address) is hop -to-hop and gets stripped out of the packet at each hop and the new Layer 2 information is added.