Skip to main content

route command

Detailed Explanation

The route command is an older tool used to view and manipulate the IP routing table in Linux. The routing table determines where network traffic is sent based on the destination IP address. While still found on many systems, route is considered obsolete and has been superseded by the ip route command.

Basic Syntax

route [options]
route [add|del] [-net|-host] <target> [netmask <Nm>] [gw <Gw>] [metric <N>] [[dev] <If>]

Common Flags/Options

OptionDescription
-nDisplay numerical addresses instead of trying to resolve hostnames (much faster).
addAdd a new route.
delDelete a route.
-netThe target is a network.
-hostThe target is a specific host.
gwRoute packets via a gateway.

Real-world Examples

Display the current routing table:

route -n

Add a default gateway:

sudo route add default gw 192.168.1.1

Add a route to a specific network:

sudo route add -net 10.0.0.0 netmask 255.0.0.0 gw 192.168.1.254

Delete a specific route:

sudo route del -net 10.0.0.0 netmask 255.0.0.0