Hi Neha,
This question with this topology comes up every now and then so I’ll explain it in detail here. Here’s the topology with some network and IP addresses. The green addresses are (simplified) MAC addresses:
The routers are configured with two static routes:
R1:
ip route 192.168.2.0 255.255.255.0 192.168.12.2
R2:
ip route 192.168.1.0 255.255.255.0 192.168.12.1
All devices just powered up, nothing has happened yet. Let’s walk through what happens step-by-step to get an IP packet from H1 to H2.
- H1 wants to send an IP packet to H2. The source IP address is 192.168.1.1 and the destination IP address is 192.168.2.2.
- H1 creates an IP packet with source IP address 192.168.1.1 and destination IP address 192.168.2.2.
- H1 is configured with IP address 192.168.1.1 and subnet mask 255.255.255.0. It looks at 192.168.2.2 and sees that this IP address it outside of its own subnet. This means it has to send the packet to its default gateway.
- H1 creates an Ethernet frame, sets the source MAC address to AAA and now has to fill in the destination MAC address..
- H1 now checks its ARP table to see if it knows the MAC address for 192.168.1.254 (default gateway).
- Since we just powered on H1, there is nothing in the ARP table so H1 creates an ARP request packet where it asks for the MAC address of 192.168.1.254.
- The ARP request is encapsulated in an Ethernet frame with source MAC address AAA and destination MAC address is broadcast (FF:FF:FF:FF:FF:FF).
- H1 sends the Ethernet frame out of its interface onto the LAN.
- SW1 now receives the Ethernet frame containing the ARP request from H1.
- SW1 looks at the source MAC address (AAA) and stores this in its MAC address table for interface Gi0/1.
- SW1 looks at the destination MAC address, this is a broadcast so it is flooded on all its interfaces except the interface where it originated from. The frame is forwarded out of interface Gi0/2.
- R1 receives the Ethernet frame with the encapsulated ARP request
- R1 looks at the destination MAC address, which is a broadcast so it will process the Ethernet frame. R1 de-encapsulates the ARP request.
- R1 stores an entry in its ARP table for 192.168.1.1 and MAC address AAA.
- Looking at the ARP request, R1 comes to the conclusion that 192.168.1.254 is its own IP address so it has to reply with an ARP reply.
- The ARP reply contains the MAC address of R1 (BBB) and its IP address (192.168.1.254).
- The ARP reply is encapsulated in an Ethernet frame with source MAC address BBB and destination MAC address AAA.
- The Ethernet frame with the encapsulated ARP reply is forwarded out of the Gi0/2 interface of R1.
- SW1 receives the Ethernet frame with the encapsulated ARP reply.
- SW1 looks at the source MAC address (BBB) and stores this in its MAC address table for interface Gi0/2.
- SW1 looks at the destination MAC address (AAA), does a lookup in its MAC address table and sees that MAC address AAA should be forwarded out of interface Gi0/1.
- SW1 forwards the Ethernet frame out of interface Gi0/1.
- H1 receives the Ethernet frame with the encapsulated ARP reply. It looks at the destination MAC address, sees that this is its own MAC address and de-encapsulates the ARP reply.
- H1 processes the ARP reply and now knows that IP address 192.168.1.254 can be reached with MAC address BBB. This is stored in the ARP table.
- H1 now encapsulates the IP packet that our story started with into an Ethernet frame, enters AAA as the source MAC address and BBB as the destination MAC address. The Ethernet frame is forwarded out of its interface.
- SW1 receives the Ethernet frame, looks at the destination MAC address (BBB) and forwards the Ethernet frame out of its Gi0/2 interface.
- R1 receives the Ethernet frame, looks at the destination and sees that the destination MAC address is its own MAC address. It de-encapsulates the IP packet.
- R1 now looks at the destination IP address of the IP packet which is 192.168.2.2.
- R1 now looks in the routing table to see if there any networks that match this destination. We have a static route for 192.168.2.0/24 pointing to next hop IP address 192.168.12.2.
- R1 now looks in its ARP table to see if it knows the destination MAC address for 192.168.12.2.
- Since there is nothing in the ARP table, it creates an ARP request for 192.168.12.2.
- R1 encapsulates the ARP request in an Ethernet frame, sets the source MAC address to CCC and destination MAC address to broadcast (FF:FF:FF:FF:FF:FF).
- R1 forwards the Ethernet frame out of its Gi0/1 interface.
- R2 receives the Ethernet frame, looks at the destination and since this is a broadcast, it de-encapsulates the frame and finds the ARP request.
- R2 now stores IP address 192.168.12.1 and MAC address CCC in its ARP table.
- R2 creates an ARP reply, enters its source MAC address (DDD) and IP address (192.168.12.2) and encapsulates the ARP reply in an Ethernet frame. The source MAC address is DDD and destination MAC address is CCC.
- R2 forwards the Ethernet frame out of its Gi0/1 interface.
- R1 receives the Ethernet frame, looks at the destination which is CCC and de-encapsulates it to find the ARP reply.
- R1 now stores IP address 192.168.12.2 and MAC address DDD in its ARP table.
- R1 encapsulates the IP packet it received from H1 in an Ethernet frame, sets the source MAC address to CCC and destination MAC address to DDD.
- R1 forwards the Ethernet frame out of its Gi0/1 interface.
- R2 receives the encapsulated IP packet from R1, looks at the destination MAC address and sees DDD is the destination.
- R2 de-encapsulates the IP packet out of the Ethernet frame and looks at the destination (192.168.2.2).
- R2 looks in its routing table to find a match for 192.168.2.2. The 192.168.2.0/24 network is directly connected on its Gi0/2 interface so there is a match.
- Since the network is directly connected, R2 and H2 are in the same subnet. This means R2 can deliver it directly to H2.
- R2 looks in its ARP table to see if it knows what the MAC address is for 192.168.2.2. There is no entry so it will create an ARP request for 192.168.2.2.
- R2 encapsulates the ARP request in an Ethernet frame, sets the source MAC address to EEE and destination to broadcast (FF:FF:FF:FF:FF:FF).
- R2 forwards the Ethernet frame out of its Gi0/2 interface.
- SW2 receives the Ethernet frame.
- SW2 looks at the source MAC address (EEE) and stores this in the MAC address table for interface Gi0/2.
- SW2 looks at the destination MAC address, sees it's a broadcast and floods the frame out of all interfaces except the one it originated from.
- H2 now receives the Ethernet frame, looks at the destination MAC address, sees it's a broadcast and de-encapsulates the frame.
- H2 sees the frame has an ARP reply and stores the MAC address (EEE) and IP address (192.168.2.254) in its ARP table.
- H2 creates an ARP reply, encapsulates it in an Ethernet frame and sets the source MAC address to FFF and destination MAC address to EEE.
- H2 forwards the Ethernet frame out of its interface.
- SW2 receives the Ethernet frame.
- SW2 stores the source MAC address (FFF) in its MAC address table for interface Gi0/1.
- SW2 does a lookup for destination MAC address (EEE) and forwards the Ethernet frame out of its Gi0/2 interface.
- R2 receives the Ethernet frame, looks at the destination MAC address (EEE) and since this is its MAC address, it de-encapsulates the Ethernet frame.
- R2 processes the ARP reply and stores IP address 192.168.2.2 and destination MAC address FFF in its ARP table.
- R2 now has everything it needs to forward the IP packet. It encapsulates the IP packet in an Ethernet frame, sets the source MAC address to EEE and destination MAC address to FFF.
- R2 forwards the Ethernet frame out of its Gi0/2 interface.
- SW2 receives the Ethernet frame, does a lookup in its MAC address table for FFF, finds a match, forwards the Ethernet frame out of its Gi0/1 interface.
- H2 receives the Ethernet frame, looks at the destination and sees that FFF is its MAC address.
- H2 de-encapsulates the Ethernet frame and finds the IP packet.
- H2 sees the destination IP address is 192.168.2.2 and de-encapsulates the IP packet. If this is an ICMP request, it will want to respond.
The return path works exactly the same except all ARP tables are now filled so there’s no need for the ARP request/reply. The switches have all MAC addresses in their MAC address tables so they can do a lookup.
https://networklessons.com/cisco/ccnp-route/arp-address-resolution-protocol-explained/
https://networklessons.com/switching/how-does-a-switch-learn-mac-addresses/
https://networklessons.com/cisco/ccna-routing-switching-icnd1-100-105/ip-routing-explained/
I hope this is helpful!
Rene