How to View the Routing Table in Ubuntu?

To view the network routing table on an Ubuntu machine, you can use several commands depending on your system version and preference, with ip route being the modern standard. This article provides a quick overview of the primary commands used to check routing paths, explains how to interpret their output, and details how to filter the results to find your default gateway.


The Modern Standard: ip route

The most common and recommended way to check the routing table on modern Ubuntu systems is the ip command. It is part of the iproute2 suite, which comes pre-installed on all recent Ubuntu releases.

To see the full routing table, open your terminal and type:

ip route

Alternatively, you can use the shorthand version:

ip r

Understanding the ip route Output

When you run this command, you will see lines of text representing different routing rules. A typical output looks like this:

default via 192.168.1.1 dev eth0 proto dhcp src 192.168.1.50 metric 100 
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.50 metric 100 

Legacy Alternatives: route and netstat

If you are working on older Ubuntu versions or prefer traditional networking tools, you can use the route or netstat commands. Note that these tools are deprecated and may require you to install the net-tools package first via sudo apt install net-tools.

Using the route Command

To display the routing table in a traditional format, run:

route -n

Using the netstat Command

Another classic approach to viewing the routing table is using the network statistics tool:

netstat -rn

Filtering for the Default Gateway

If your routing table is large and you only want to quickly identify your default gateway (the router connecting you to the internet), you can pipe the output to grep:

ip route show default

Or using the legacy command:

route -n | grep '^0.0.0.0'