Skip to main content
SysAdmin Shell Scripting Essentials

Linux Show Routes CLI Command Reference: Syntax, Flags, Examples

linux show routes is the command to display the kernel routing table using ip route show, route -n, or netstat -rn.

$ ip route list 192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.103ndefault via 192.168.0.1 dev eth0

Syntax

# Modern method (iproute2, recommended)
ip route show [ OPTIONS ] [ SELECTOR ]

# Legacy methods (deprecated but still present)
route -n
netstat -rn

Options and Flags

Flag Command Type Default Description
--all, -a, -all ip route show Filter Show all Display all routes (default behavior).
-t ip route show Filter Show all Display routes with timestamps.
to PREFIX ip route show Selector All Show routes to a specific destination prefix (e.g., to 192.168.1.0/24).
table TABLE ip route show Selector main Show routes from a specific routing table (e.g., table local, table 100).
-n route, netstat Format Hostname resolution Show numerical addresses (no DNS lookups).
-rn netstat Format Hostname resolution Display routing table numerically.

Usage Examples

List all IPv4 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
$ 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
$ 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

Troubleshooting & Common Errors

Error Message Root Cause Resolution Command
RTNETLINK answers: Network is unreachable No route to destination, or outbound interface down.
ip link set eth0 upnip route add default via 192.168.1.1
SIOCADDRT: Network is unreachable Trying to add a route via a gateway that is not reachable.
ping -c 1 192.168.1.1
Destination Host Unreachable (from route command) Kernel cannot find a route to the destination host.
ip route get 10.0.0.5
No output from ip route show (empty table) Interface has no IP configuration, or kernel routing table wiped.
ip addr showndhclient eth0

Frequently Asked Questions

What is the difference between ip route and route -n in Linux?

Answer: ip route is part of iproute2 suite, offers JSON output and advanced features; route -n is legacy net-tools, displays numeric addresses. ip route show provides structured output, supports filtering by table, protocol, and route type. route -n does not support VRF or multiple routing tables. Modern distributions deprecate route. Use ip route for scripting and consistency across kernels.

See also  PowerShell Rename-Item: Syntax, Examples & Troubleshooting

When should I use the -6 flag with ip route?

Answer: Use ip -6 route show to display IPv6 routing table entries. Without -6, only IPv4 routes appear. Combine with show and optional dev <interface> to isolate per-interface IPv6 routes. Example: ip -6 route show dev eth0.

How do I fix "RTNETLINK answers: Network is unreachable" when showing routes?

Answer: This error indicates a missing default gateway or interface down. Check routing table: ip route show table main. Ensure default via exists. If missing, configure: ip route add default via 192.0.2.1 dev eth0. For persistent config, use nmcli or distro-specific files.

Does ip route show work identically on AWS EC2, Azure VM, and GCP Compute Engine?

Answer: Yes, base Linux ip route behavior is identical across clouds, but cloud-specific virtual network interfaces (e.g., ENI) may present routes via DHCP or SDN. Use ip route show to view routes. Cloud metadata services provide custom routes via DHCP or SDN controllers. No cloud-specific flags are needed; however, inspect ip route show table local for local routes assigned by your cloud provider.

What is the fastest way to display only default routes in Linux?

Answer: Use ip route show default to output all default routes (IPv4 and IPv6) immediately, with zero filtering overhead. This command leverages kernel route matching. For a formatted one-liner: ip route show default | awk '{print $3}' extracts gateway IP. To include metric: ip route show default | head -1. Avoid grepping ^default for speed.