Monday, May 5, 2008

How to Display Routing Table

To display the kernel routing table, you can use any of the following methods:

  • route
    $ 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
    $ 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
    $ 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


4 comments:

Rossano said...

You don't need to be root to execute route.
Use the full path of the command.

$ /sbin/route

Anonymous said...

But you have 5 routing tables. How to Display e.g local or default by route command??
I know you can do it with the ip command ( ip route show table main, ip route show table local )

Anonymous said...

you don't, route is hard wired to show the main table

Self-hosted LMS said...

Thanks for this post!