Skip to main content

Module 9: Networking

Lesson 96: route Command

In this lesson, you'll learn how to use the route command to view, add, delete, and manage the IP routing table on your Linux system.

The route command reads and writes to the kernel's IP routing table a set of rules that the kernel consults for every outbound packet to decide which network interface and gateway to use.

When you type ping google.com, the kernel checks the routing table before the first packet is ever sent.

If no matching route exists, the packet is dropped immediately with a "Network is unreachable" error, never reaching the network at all.

Understanding and managing the routing table is a fundamental sysadmin skill for configuring multi-homed servers, setting up VPN routing, isolating traffic by interface, and diagnosing connectivity failures that ping and traceroute alone cannot explain.

πŸ’‘
Note: The route command is part of the legacy net-tools package. On modern Linux systems, it has been superseded by the ip route command from the iproute2 package, which is more powerful and consistent.

Both are covered in this lesson route for familiarity with older systems and documentation, ip route as the modern equivalent you should use going forward.

Installation

sudo apt install net-tools          # Debian/Ubuntu

Or:

sudo dnf install net-tools          # Fedora/RHEL 9+

Syntax

route [OPTIONS]
route add [OPTIONS] TARGET
route del [OPTIONS] TARGET

Options

Option Description
-n Show IP addresses numerically β€” skip DNS resolution
-v Verbose output
-e Display the routing table in netstat format
-4 Show IPv4 routing table only
-6 Show IPv6 routing table only
add Add a new route
del Delete an existing route
-net Target is a network address
-host Target is a host address
gw Specify the gateway for the route
metric Set the route priority (lower = preferred)
dev Specify the network interface

Understanding the Routing Table Output

route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    100    0        0 enp0s3
192.168.0.0     0.0.0.0         255.255.255.0   U     100    0        0 enp0s3
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

Each row is a routing rule. Here is what every column means:

Column What It Means
Destination The target network or host this rule applies to
Gateway Where to send the packet next (0.0.0.0 means directly connected β€” no gateway needed)
Genmask The subnet mask for the destination network
Flags Route status flags (see table below)
Metric Route priority β€” lower value is preferred when multiple routes match
Ref Number of references to this route (legacy, usually 0)
Use Number of times this route has been used
Iface The network interface packets leave through

Route flags:

Flag Meaning
U Route is Up (active)
G Route uses a Gateway
H Target is a Host (not a network)
R Route was reinstated dynamically
D Route was created dynamically by a daemon
M Route was modified by a routing daemon
! Route is rejected (blocked)
πŸ’‘
Note: The default route (also shown as 0.0.0.0 destination with 0.0.0.0 Genmask) is the gateway of last resort; all packets that don't match any more specific route are sent here.

A missing default route means the system can only communicate with directly connected networks.

1. View the Kernel Routing Table

route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         gateway         0.0.0.0         UG    100    0        0 enp0s3
192.168.0.0     0.0.0.0         255.255.255.0   U     100    0        0 enp0s3
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0

The three routes in this typical output tell you:

  • default via gateway on enp0s3 β€” all non-local traffic goes to the ISP/router gateway
  • 192.168.0.0/24 on enp0s3 β€” packets to this local network go directly out enp0s3 without a gateway
  • 192.168.122.0/24 on virbr0 β€” traffic to the KVM virtual bridge network goes through the virbr0 interface

2. Show Numeric IP Addresses Only

Pro TecMint Β· Root Plan
This Article is for Root Members
Join Root to read the full article and unlock everything

Full Access to Every Article, Course & Certification Track

Join thousands of Linux professionals who use Pro TecMint to advance their careers.

Ad-free access to all premium articles
All courses: Learn Linux, Bash, Golang, Ubuntu and more
RHCSA, RHCE, LFCS & LFCA certification prep
New courses added every month
Private Telegram community & priority support
Root Plan
$8/mo
or $59/year billed annually
Save $37 with annual plan
Start Reading This Article in the Next 60 Seconds
Join Root Plan β†’