How a Router Routes
This tutorial will be going over the basic information of how a router routes IP packets. Routers are used in the OSI layer three or the network layer. These routers have IP addresses and forward IP packets to the proper destination. This guide is somewhat basic and is assuming you have some information of how IP addressing works and along with what routing protocols are. So let's focus first on how a host or a computer forwards traffic and then look at how a router forwards traffic. Computers forward or send packets based on these two steps.
-
If the destination IP address is in the same network or subnet as PC-1 then send the packet directly to that host (without the routers help)
- If PC-1 does not have the MAC address to the destination host (PC-2) then it will send an ARP request to get the MAC address.
-
If the destination IP address is not in the same subnet or network has PC-1 then PC-1 will send the packet to its default gateway.
- If PC-1 does not have the MAC address to the default gateway (R1) then send a ARP request to get the MAC address
For example PC-1 (192.168.1.1) is trying to send to R1 (192.168.1.254) because the packet is not in the same network, PC-1's main goal is to send to a webserver (154.63.2.1) (PC-1 checks the destination subnet mask and IP address to see if they are on the same network which they are not) if PC-1 knows the MAC address of R1 it will put the IP address of R1 in the destination address field along with other information not related to this tutorial, and forward the packet. If PC-1 does not know the MAC address it will send and ARP request, what this request does is send a broadcast message to all other PCs and devices connected on the 192.168.1.0 network. This message wants to find the MAC address of the host connected to 192.168.1.254, once R1 gets the message it will send its MAC address to PC-1. PC-1 will then forward the packet/frame. Once the frame is received by R1 the router will first check the data-link FCS field. If the frame received errors the router will drop the packet. If the frame has no errors the router will rip off the old data link header and trailer and then look at the IP packet. The router then compares the IP packet's destination address. If the router has the IP address in its routing table the router will encapsulate the IP packet inside a new data link layer header and trailer and forward it out the correct interface, thus forwarding the frame. Confusued? Let's go into some more detail of what happened.