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

Pasted image 20240910235108.png

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

Pasted image 20240910235654.png

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

Pasted image 20240911000457.png

Example

Pasted image 20240911000546.png

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

Pasted image 20240911000631.png

If it's sending a packet that does not in the Routing table, for example 10.0.44.9 to R2

Pasted image 20240911000700.png

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.

Pasted image 20240911000913.png

Pasted image 20240911000924.png

Now it will know to forward to packet to 10.0.55.1 which will use the Right interface

Pasted image 20240911000958.png

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.

Pasted image 20240911001058.png

Now it's time for us to setup the Static Route for R1 as well

Pasted image 20240911001130.png

Now R1 will know to send it to R2

Pasted image 20240911001144.png

R2 knows to send it to Host C

Pasted image 20240911001223.png

Another way is to use Dynamic Route in Routing Table. Which the 2 routers automatically share which subnet it's missing to eachother

Pasted image 20240911001441.png

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

Pasted image 20240915131250.png

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
Pasted image 20240917211220.png

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.

Pasted image 20240917211746.png

Therefore, host A send an ARP (Address Resolution Protocol) request

Pasted image 20240917212242.png

When R1 receives the ARP (Address Resolution Protocol), it can populate its ARP table

Pasted image 20240917212327.png

Now R1 will then reply to Host A.

Pasted image 20240917212358.png

Now HostA can populate its ARP Table and generate the L2 Header

Pasted image 20240917212424.png

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)

Pasted image 20240917212809.png

Now R2 can populate its ARP Table since it receives the ARP (Address Resolution Protocol) request. That router R1 has mac address eee3

Pasted image 20240917213431.png

Now it will generate an ARP response:

Pasted image 20240917213453.png

Now R1 can add 10.0.55.2 -> eee2 to its ARP Table and generate the L2 header to send R2

Pasted image 20240917213555.png

R2 then receives the packet and discard L2 header.

Pasted image 20240917214417.png

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.

Pasted image 20240917214801.png

Host C adds R2 mac address and generate an ARP (Address Resolution Protocol) response.

Pasted image 20240917214832.png

R2 will then populate the ARP response mac address

Pasted image 20240917214900.png

Now Host C will receive this packet:

Pasted image 20240917214926.png

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.

Pasted image 20240917215035.png

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

Pasted image 20240917215554.png

Once R2 receives the packet, it discard L2 Header, And then it looks for where it should route next

Pasted image 20240917215651.png

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

Pasted image 20240917215746.png

L1 once receives will then also discard the L2 table.

Pasted image 20240917215802.png

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

Pasted image 20240917215936.png

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