For packet sending over the routed network, the IP address of destination network required. If the destination address belongs to the same network, and then the source does not use the default gateway. The host applies AND operation for determining the network address. I have already discussed the AND operation in my earlier article ANDing and Determining Network Address.
If the destination belongs to the same network, then the source device uses its ARP cache for the MAC address of the destination. If the MAC address not listed in the ARP cache then the source generates an ARP request to acquire the MAC address to complete the packet sending to the destination.
When a packet completed, router send it to the destination. If the destination network address belongs to a different network, then source consults its ARP cache for gateway MAC address, if the MAC address listed in the ARP cache the source forwards the packet to its default gateway. If the address is not listed in ARP cache; then the source first generates ARP request to get the MAC address of the gateway and then send the packet to the gateway for further processing. See the video for the complete operation of a packet sending.
In the video, you can see the Laptop 0 packet sending to the webserver. The Laptop 0 first determines that the destination IPv4 address is not on the same network. So, Laptop 0 check for default gateway IP address and MAC address. The MAC address is not listed in ARP cache of Laptop 0; So Laptop 0 generate ARP request for acquiring the MAC address of the default gateway. When Laptop 0 received MAC address then the Laptop 0 encapsulates the layer3 Packet into layer2 frames and sends it to Layer1. The Layer 1 send Layer 2 frame in shape of Ethernet frame (0 and 1).
The IPv6 also uses a similar procedure for IPv6 packets. But in place of the ARP process, IPv6 address resolution uses ICMPv6 Neighbor Solicitation and Neighbor Advertisement messages. IPv6-to-MAC address mapping is kept in a table similar to the ARP cache, called the neighbor cache.
Packet Forwarding and Routing
When Router1 receives the Ethernet frames from Laptop 0. The Router1 examines the destination MAC address, which matches the MAC address of the Router receiving interface Gig0/1. So, Router1 copies the frame into its buffer. The router identifies the frame type field as 0x800, which indicates that the frame has an IPv4 packet in the data part. The router de-encapsulates the Ethernet frame to check the destination IPv4 address.
When examining that the destination address does not match any of the directly connected interfaces of the Router1. The Router1 then searches the routing table for matching the destination address network. When the address matched to any of network address in the routing table, the router selects an outgoing interface for the packet.
When the router selects an outgoing interface, For example, in the video; the destination address is matching to route 192.168.10.0/24. The exit interface for 192.168.10.0/24 is Gig0/0, so, the router encapsulates the packet in Ethernet layer 2 frames. The frame included source MAC address and destination MAC address. The router1 exit interface Gig0/0 is a source and router-2 interface Fa0/0 is the destination for layer-2 frames this time.
When Router2 receives the Ethernet frame from Router1. It examines the MAC address and de-encapsulates the layer 2 frames to check the layer3 information. Then search the proper route in the routing table for address 192.168.10.2. This time the exit interface is serial port s0/3/0. The router encapsulates the layer2 frame this time for a serial port which protocol is PPP. The PPP frames not use MAC addresses. Each router is doing the same procedure with the packet sending until the original destination mentioned in layer 3 information, received the packet.
Reach the Destination
When the packet arrives at router4 directly connected network 192.168.10.0/24. The Router4 copies the data link Ethernet frame into its buffer and de-encapsulates the data link Ethernet frame. The Router3 searches the routing table for the destination IPv4 address of the packet. The routing table has a route to a directly connected network on Router4. So, the Router4 sent the packet directly to the destination.
The exit interface is directly connected to the Ethernet network; So, the router must resolve the destination IPv4 address of the packet with a destination MAC address. The Router4 searches for the destination IPv4 address of the packet in its ARP cache. If the entry is not in the ARP cache; the Router4 sends an ARP request out of its Fast Ethernet 0/0 interface. The Web Server sends back an ARP reply with its MAC address. Router4 then updates its ARP cache with an entry for 192.168.10.2 and the MAC address that is returned in the ARP reply.
The IPv4 packet is encapsulated into a new Ethernet data link frame and sent out to the Fast Ethernet 0/0 interface. When Web Server receives the frame, it examines the destination MAC address in the frame; which matches the MAC address of the receiving interface; its Ethernet network interface card (NIC). Then the Web Server copies the rest of the frame into its buffer and identifies the Ethernet Type field as 0x800; which means that the Ethernet frame has an IPv4 packet in the data portion. It de-encapsulates the Ethernet frame and passes the IPv4 packet to the IPv4 process of its operating system and send a reply according to the packet.