Enhance your Career in Networking With IPinBits!!!​

Linux for network engineers – Routing tables

Well almost all routers/switches are Linux based (Free BSD in most cases). In this post we will study about the routing tables which linux manages. Till now you must have heard about the RIB/FIB in a router, linux routing table is derived from that only. From my TAC days, i remember handling a task where verything was perfect :-
1. Routing protocol was working fine.
2. Routes were in RIB/FIB.
3. No arp issue.

But still there were no ping between the endpoints. What could go wrong if both sides have ip routes and there is no firewall blocking any port/protocol in-between. Well the issue was related to routing table in Linux. Yes, route was missing from linux table even though you could see the route in Normal CLI RIB/FIB. 

So let’s see how do we check the linux routing tables.

1. How do we check the linux RIB

ipinbits@ubuntu:~$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.200.2   0.0.0.0         UG    100    0        0 ens33
link-local      *               255.255.0.0     U     1000   0        0 ens33
192.168.200.0   *               255.255.255.0   U     100    0        0 ens33

 2. Lets check the FIB

ipinbits@ubuntu:~$ route -F
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.200.2   0.0.0.0         UG    100    0        0 ens33
link-local      *               255.255.0.0     U     1000   0        0 ens33
192.168.200.0   *               255.255.255.0   U     100    0        0 ens33

We have other ways to check linux routing tables also, most popular is 

ipinbits@ubuntu:~$ netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         192.168.200.2   0.0.0.0         UG        0 0          0 ens33
169.254.0.0     0.0.0.0         255.255.0.0     U         0 0          0 ens33
192.168.200.0   0.0.0.0         255.255.255.0   U         0 0          0 ens33

Option -r  is to display the routing table
Option -n is not to resolve the names. Print the IP addresses only.

Last but not the least, we have below familiar command :-

ipinbits@ubuntu:~$ ip route
default via 192.168.200.2 dev ens33  proto static  metric 100 
169.254.0.0/16 dev ens33  scope link  metric 1000 
192.168.200.0/24 dev ens33  proto kernel  scope link  src 192.168.200.130  metric 100 

We checked same info using the three commands. Have some routers spin up in lab and try it yourself. Some extra info about the commands are as below 

ipinbits@ubuntu:~$ route --help
Usage: route [-nNvee] [-FC] [<AF>]           List kernel routing tables
       route [-v] [-FC] {add|del|flush} ...  Modify routing table for AF.
       route {-h|--help} [<AF>]              Detailed usage syntax for specified AF.
       route {-V|--version}                  Display version/author and exit.
        -v, --verbose            be verbose
        -n, --numeric            don't resolve names
        -e, --extend             display other/more information
        -F, --fib                display Forwarding Information Base (default)
        -C, --cache              display routing cache instead of FIB
  <AF>=Use '-A <af>' or '--<af>'; default: inet
  List of possible address families (which support routing):
    inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25) 
    netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP) 
ipinbits@ubuntu:~$ netstat --help
usage: netstat [-vWeenNcCF] [<Af>] -r         netstat {-V|--version|-h|--help}
       netstat [-vWnNcaeol] [<Socket> ...]
       netstat { [-vWeenNac] -i | [-cWnNe] -M | -s }
        -r, --route              display routing table
        -i, --interfaces         display interface table
        -g, --groups             display multicast group memberships
        -s, --statistics         display networking statistics (like SNMP)
        -M, --masquerade         display masqueraded connections
        -v, --verbose            be verbose
        -W, --wide               don't truncate IP addresse
        -n, --numeric            don't resolve names
        --numeric-hosts          don't resolve host names
        --numeric-ports          don't resolve port names
        --numeric-users          don't resolve user names
        -N, --symbolic           resolve hardware names
        -e, --extend             display other/more information
        -p, --programs           display PID/Program name for sockets
        -c, --continuous         continuous listing
        -l, --listening          display listening server sockets
        -a, --all, --listening   display all sockets (default: connected)
        -o, --timers             display timers
        -F, --fib                display Forwarding Information Base (default)
        -C, --cache              display routing cache instead of FIB
    List of possible address families (which support routing):
    inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25) 
    netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP) 
    x25 (CCITT X.25) 
ipinbits@ubuntu:~$ ip --help
Usage: ip [ OPTIONS ] OBJECT { COMMAND | help }
ip [ -force ] -batch filename
where OBJECT := { link | address | addrlabel | route | rule | neighbor | ntable |
tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm |
netns | l2tp | fou | tcp_metrics | token | netconf }
OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |
-h[uman-readable] | -iec |
-f[amily] { inet | inet6 | ipx | dnet | mpls | bridge | link } |
-4 | -6 | -I | -D | -B | -0 |
-l[oops] { maximum-addr-flush-attempts } | -br[ief] |
-o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |
-rc[vbuf] [size] | 
-n[etns] name | -a[ll] | -c[olor]}

Related blog posts