To display the kernel routing table, you can use any of the following methods:
List all the current static routes:
$ sudo route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
You need to be root to execute route. The -n option means that you want numerical IP addresses displayed, instead of the corresponding host names.
netstat is another easy command that can be used to display the static routes.
$ netstat -rn Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 192.168.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 0.0.0.0 192.168.0.1 0.0.0.0 UG 0 0 0 eth0
The -r option specifies that you want the routing table. The -n option is similar to that of the route command.
ip command can be used to display IPv4 as well as IPv6 routing tables. The below command displays the IPv4 routing table.
$ ip route list 192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.103 default via 192.168.0.1 dev eth0
$ ip route default via 10.0.2.2 dev eth0 proto dhcp metric 100 10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15 metric 100 172.16.0.0/12 via 192.168.33.11 dev eth1 192.168.33.0/24 dev eth1 proto kernel scope link src 192.168.33.10 metric 101
How to view IPv6 routes
To view IPv6 routing table, use the command:
# ip -6 route
For more information on ip command, see the man page:
# man ip
When the route -n command is issued, there is an address listed of “0.0.0.0”. This entry in the route table indicates the route to the Default Gateway. As an outgoing packet is created, the destination address is assigned. The kernel will examine the current routing table from top to bottom. If no matches are found for the destination address the packet will be sent through the default gateway. The address seen of 0.0.0.0 indicates a match for everything. The four 0’s act as wildcards in an IP address.
For example, given the routing table below, any packet not destined for the 192.168.122.0/24 network will be sent to the default gateway of 192.168.122.1 through the eth0 interface:
# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 192.168.122.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0 0.0.0.0 192.168.122.1 0.0.0.0 UG 0 0 0 eth0