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
| Destination | Gateway | Genmask | Flags | Interface |
|---|---|---|---|---|
| 0.0.0.0 | 140.112.30.254 | 0.0.0.0 | UG | eht0 |
| 140.112.30.0 | 0.0.0.0 | 255.255.255.0 | U | eth0 |
Destination
Destination IP
Gateway
The gateway tells us how can we get out of the local network to the outside world
For example:
- 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.254will handle traffic going out - 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 activeG= Route uses a gatewayH= 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.254route add= the command to add routedefault= the route we add is default gatewaygw 140.112.30.254= the gateway is140.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= destinationnetmask 255.255.255.192= netmaskgw 140.112.30.123= gateway