Network

The route command

Shows and edits the routing table: which interface and which gateway the system uses to reach each network. It is the classic net-tools command. Today ip route replaces it, but route is still on many servers and in older documentation, so it is worth recognising its output.

Syntax

route [-nv] | route add|del ...Try it in the terminal →

Most useful options

-nShows IPs as numbers, without resolving names. Faster and cleaner
-vVerbose mode: shows more information when adding or deleting routes
-eExtended format, with more columns such as metric and use
-A <familia>Chooses the address family: -A inet6 for IPv6

Copy-ready examples

$ route -nrouting table in numeric format. The 0.0.0.0 line with G is the default gateway.

Example output

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    600    0        0 wlp3s0
192.168.1.0     0.0.0.0         255.255.255.0   U     600    0        0 wlp3s0
$ sudo route add -net 10.8.0.0 netmask 255.255.255.0 gw 192.168.1.10sends traffic for 10.8.0.0/24 through 192.168.1.10. It lasts until the next reboot.
$ sudo route add default gw 192.168.1.1sets the default gateway. If one already exists, it fails with SIOCADDRT: File exists.
$ sudo route del defaultremoves the default gateway. If there is no other one, the machine loses its way out to the Internet.

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
SIOCADDRT: File existsThe route already exists. Adding the same route twice gives this error.Check the table with route -n before adding, or delete the old one with route del.
SIOCDELRT: No such processYou tried to delete a route that does not exist, for example because you wrote it differently.Copy the route exactly as it appears in route -n, with its mask.
SIOCADDRT: Operation not permittedChanging the routing table requires administrator privileges.Repeat the command with sudo. To only read it, you do not need it.

Typical mistakes

  • Routes added with route do not survive a reboot. To make them permanent, configure them in the system network setup (netplan, NetworkManager...).

Differences from similar commands

  • ip: ip route does the same with iproute2 syntax, which is the recommended one today.
  • arp: route says where traffic leaves; arp says which MAC answers each local IP.

Security

Changing the default route can send all of the machine's traffic somewhere else. An attacker with root access can do this unnoticed, so check route -n after any unexpected change.

Related commands

FAQ

What does G in the Flags column mean?

That the route uses a gateway. U means the route is up; H means the destination is a single host rather than a network.

What is the default route?

It is the one used by all traffic without a more specific route. It shows as 0.0.0.0 and usually leaves through the home router.

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course