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 routeAlternatively, you can use the shorthand version:
ip rUnderstanding 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
- default: Specifies the default route used when no other specific route matches the destination IP address.
- via 192.168.1.1: The IP address of the router or gateway handling the traffic.
- dev eth0: The specific network interface card (e.g., Ethernet or Wi-Fi) being used.
- proto dhcp / proto kernel: Indicates how the route was learned (dynamically via DHCP or automatically by the kernel).
- src 192.168.1.50: The source IP address assigned to your Ubuntu machine for this route.
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- The
-nflag forces the command to show numerical IP addresses instead of attempting to resolve hostnames, which makes the command run significantly faster.
Using the netstat
Command
Another classic approach to viewing the routing table is using the network statistics tool:
netstat -rn- The
-rflag tells netstat to display the routing tables, and the-nflag ensures the output remains numerical.
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 defaultOr using the legacy command:
route -n | grep '^0.0.0.0'