The routing table is used to show you where various different network subnets will be routed to. Here are three different commands that you can use to print out the routing table in Linux.
If you’re instead trying to create a new static route in Linux check out our guide here.
Using ip command
The current recommended way of printing the routing table in Linux is with the ip command followed by route, as demonstrated below.
[[email protected] ~]# ip route default via 192.168.1.254 dev eno16777736 proto static metric 100 192.168.1.0/24 dev eno16777736 proto kernel scope link src 192.168.1.14 metric 100 192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1
If you’re in a hurry you can also shorten this to ‘ip r’ which will print the same output. While this is the current recommended method of printing out the routing table in Linux, you will see that the output doesn’t look as nice as older options.
Check out our IP command examples for further information on how you can use this to display networking information.
Using netstat command
While this is a popular way of printing out routing information in Linux, netstat is actually deprecated and replaced instead with ip route – it even says so in the manual page. Nevertheless as it is still widely used, we have included it here.
Netstat combined with the -r option will display the kernel routing tables. This is commonly used with the -n option, which will only show numerical addresses rather than performing any sort of name resolution.
[[email protected] ~]# netstat -rn Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 0.0.0.0 192.168.1.254 0.0.0.0 UG 0 0 0 eno16777736 192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eno16777736 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
Using route command
The manual page for route also states that it is obsolete and has been replaced by the ip route command previously mentioned, again as this is still used, here’s an example of it. Like netstat, the -n option is used to display numeric information only.
[[email protected] ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.1.254 0.0.0.0 UG 100 0 0 eno16777736 192.168.1.0 0.0.0.0 255.255.255.0 U 100 0 0 eno16777736 192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
As we have seen there are a few ways to display the routing information in Linux, however most are now considered obsolete with ‘ip route’ being the current recommended method, despite the output in my opinion not looking as neat as the others.