Routing Table

Function

When a packet is send in, we match its destination IP with the routing table to decide which interface should we use to pass it out

Implementation

DestinationGatewayGenmaskFlagsInterface
0.0.0.0140.112.30.2540.0.0.0UGeht0
140.112.30.00.0.0.0255.255.255.0Ueth0

Destination

Destination IP

Gateway

The gateway tells us how can we get out of the local network to the outside world

For example:

  1. The first row of the table tells us “for any destination that can’t find a specific route on this router, send to 140.112.30.254”. 140.112.30.254 will handle traffic going out
  2. The second row tells us “for any destination is 140.112.30.0/24, your destination is in the local network (0.0.0.0)“. Next, we use ARP to find MAC address for the destination IP and send the packet directly to it

Routing table doesn't record path to local network devices because it only record Network Layer infos

Genmask

Subnet mask

Flag

  • U = Route is active
  • G = Route uses a gateway
  • H = Route to a specific host (only one specific destination IP can go, i.e., genmask = 255.255.255.255)

Interface

Tells which physical connection we use to send packets for that route


Command

View Route Table

netstat -nr
netstat -r
  • -nr: show routing table data with IP address
  • -r: try to show hostname of IP address, i.e., will try to do reverse DNS lookup before showing

Add route to routing table

route add default gw 140.112.30.254
  • route add = the command to add route
  • default = the route we add is default gateway
  • gw 140.112.30.254 = the gateway is 140.112.30.254
route add -net 132.236.220.64 netmask 255.255.255.192 gw 140.112.30.123
  • -net 132.236.220.64= destination
  • netmask 255.255.255.192 = netmask
  • gw 140.112.30.123 = gateway