Router
Layer: Network Layer
Establish a local network and handle traffic between your devices. Use to connect to the modem.
Router could be ethernet only, not limited to just wifi.
Router also have a NIC (Network interface card) which means it has a MAC address and an IP address.
A typical network could look like this where the Router will connect to Network Switch
Difference between router and a host
Router when receive a packet with dst
mac address or ip !=
to itself will still try to do something with that packet while host doesn't
Network to Network
For example if we want to connect to networks, the Router needs to have each own IP and Mac address designated for each network
To deal with this, Router will store a Routing Table. Each Router will have each own Routing Table and use its own Routing Table to move packet
Example
If we have a packet shows up to R2, it will use its routing table to determine where the packet should go. In this case go to the Right interface
If it's sending a packet that does not in the Routing table, for example 10.0.44.9
to R2
At this point, R2 does not know 10.0.44.9
exists, it will drop this packet.
In this case, we need to use Static Route in Routing Table to manually specify where the direction the router can transfer the packet to.
Now it will know to forward to packet to 10.0.55.1
which will use the Right
interface
Now in R1, it knows that 10.0.44.9
needs to go to Host A
Now when Host A
replies R1 will not know where to go.
Now it's time for us to setup the Static Route for R1 as well
Now R1 will know to send it to R2
R2 knows to send it to Host C
Another way is to use Dynamic Route in Routing Table. Which the 2 routers automatically share which subnet it's missing to eachother
These dynamic routing protocol are for example BGP (Border Gateway protocol), RIP, EIGRP, OSPF, IS-IS
Host to Host from different network
Note: Not only Routing Table, router also have ARP Table
For ARP table, it will store the connections of the host within the network, and the MAC Address and IP of another router.
For example Host A wants to send packet to Host C. Prepare the packet
Host A knows that Host C ip is not in the same network. Therefore it needs to send to the default gateway (.1
).
However, Host A does not know MAC address of default gateway and therefore doesn't know how to construct the L2 Header.
Therefore, host A send an ARP (Address Resolution Protocol) request
When R1 receives the ARP (Address Resolution Protocol), it can populate its ARP table
Now R1 will then reply to Host A.
Now HostA can populate its ARP Table and generate the L2 Header
Router then discard Layer 2 Header. It try to determine, the destination to go. In here that it knows since we're looking for 10.0.66.7
, which belongs to 10.0.66.x/24
. Because of that it needs to go to 10.0.55.2
It then contruct a L2 Header. However it doesn't know what's the MAC address of 10.0.55.2
. Therefore it will perform an ARP (Address Resolution Protocol)
Now R2 can populate its ARP Table since it receives the ARP (Address Resolution Protocol) request. That router R1 has mac address eee3
Now it will generate an ARP response:
Now R1 can add 10.0.55.2 -> eee2
to its ARP Table and generate the L2 header to send R2
R2 then receives the packet and discard L2 header.
Now it will need to look for 10.0.66.7
, it knows that i need to look at the left interface.
It also knows that this is the final hop because it's 10.0.66.x/24
which is the same as the interface.
However, R2 doesn't know Host C mac address, therefore it will send an ARP (Address Resolution Protocol) to find host C.
Host C adds R2 mac address and generate an ARP (Address Resolution Protocol) response.
R2 will then populate the ARP response mac address
Now Host C will receive this packet:
Host C will then discard L2 and L3 Header, and then process the data.
Now Host C will need to return back to Host A, but it will be quicker since the ARP entry has been populated.
It will create a L3 Header, since it's outside of the network, it knows that it needs to go to the default gateway.
From previously, it knows that the the default gateway MAC address is eee4 in its FIB (Forwarding information base), it then construct an L2 Header
Once R2 receives the packet, it discard L2 Header, And then it looks for where it should route next
Since 10.0.44.9
belongs to 10.0.44.x/24
subnet, it knows it needs to go to 10.0.55.1
. From the ARP Table, this is eee3
so it construct the L2 Header
L1 once receives will then also discard the L2 table.
It can see that 10.0.44.9
belongs to 10.0.44.x/24
which is its right interface. It then look in the ARP Table and was able to find that 10.0.44.9 -> a9a9
.
From here it construct the L2 header and route it to Host A
When receive, Host A will discard L2 and L3 header and process the data
[!important]
This process is the same no maters how many routers in between