LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

route

Display and manage IP routing table

TLDR

Display the routing table with numeric addresses
$ route -n
copy
Add a default gateway
$ sudo route add default gw [192.168.1.1]
copy
Add a route to a network
$ sudo route add -net [10.0.0.0] netmask [255.0.0.0] gw [192.168.1.1]
copy
Add a route to a host
$ sudo route add -host [192.168.2.100] gw [192.168.1.1]
copy
Add an IPv6 route
$ sudo route -6 add [2001:db8::/32] gw [fe80::1] dev [eth0]
copy
Delete a route to a network
$ sudo route del -net [10.0.0.0] netmask [255.0.0.0]
copy
Delete the default gateway
$ sudo route del default
copy
Add a reject route to block traffic to a network
$ sudo route add -net [10.0.0.0] netmask [255.0.0.0] reject
copy

SYNOPSIS

route [-CFvnNee] [-A family|-4|-6]route [-v] [-A family|-4|-6] add|del [-net|-host] target [netmask mask] [gw gateway] [metric N] [mss M] [window W] [irtt I] [reject] [dev interface]route [-V|--version] [-h|--help]

DESCRIPTION

route displays and manipulates the kernel IP routing table. The kernel uses routing tables to determine where to send network packets based on their destination addresses.Without arguments, route displays the current routing table. The -n flag shows numeric addresses, avoiding DNS lookups and speeding up display.Routes can be added for networks (ranges of addresses) or specific hosts. The default route (0.0.0.0/0 for IPv4) handles traffic that doesn't match any more specific route—typically pointing to the internet gateway.The gateway specified with gw must be directly reachable via an existing route before a new route through it can be added. CIDR prefix notation (e.g., 10.0.0.0/8) is supported for the target, and is equivalent to specifying a target with a netmask.Modern Linux systems prefer ip route from the iproute2 package, but route remains available for compatibility and is familiar to administrators from older systems.

PARAMETERS

-n

Show numeric addresses instead of resolving hostnames; speeds up display by avoiding DNS lookups
-v
Verbose output
-e
Display routing table in netstat(8) format; use -ee for extended output including MTU, window, and irtt columns
-C
Operate on the kernel routing cache instead of the FIB
-N
Show symbolic network names rather than CIDR notation (opposite of -n)
-4
Operate on IPv4 routes (alias for -A inet)
-6
Operate on IPv6 routes (alias for -A inet6)
-A family
Specify address family (e.g., inet, inet6)
-F
Operate on the kernel FIB (Forwarding Information Base) routing table (default)
-V, --version
Display version information
add
Add a new route
del
Delete a route
-net
Target is a network address
-host
Target is a single host address
gw gateway
Route packets via the specified gateway; the gateway must already be reachable
netmask mask
Specify the subnet mask for a network route
dev interface
Force the route to be associated with the specified network interface
metric N
Set the metric (priority) for the route; lower values are preferred
mss M
Set the TCP Maximum Segment Size (MSS) in bytes for connections using this route
window W
Set the TCP window size in bytes for connections using this route
irtt I
Set the initial round-trip time in milliseconds (1–12000) used by TCP for this route
reject
Install a blocking route that causes lookups to fail with "Network unreachable"; useful for preventing traffic to specific destinations
mod, dyn, reinstate
Diagnostic flags set by routing daemons to mark dynamic or modified routes; not normally used manually

OUTPUT COLUMNS

Destination: Target network or host addressGateway: Next-hop gateway address; `*` means the destination is directly reachable (no gateway needed)Genmask: Subnet mask for the destination; `255.255.255.255` for host routes, `0.0.0.0` for the default routeFlags: Route state flags — U=up, H=host route, G=uses a gateway, R=reinstated, D=dynamically installed, M=modified by routing daemon, A=installed by addrconf, !=reject routeMetric: Distance to the target, typically in hops; lower values are preferred when multiple routes matchRef: Number of references to this route (not used in Linux; always 0)Use: Count of route lookupsIface: Network interface used to send packets on this route

CAVEATS

Route changes made with route are not persistent across reboots. Use network configuration files or a network manager (such as NetworkManager or systemd-networkd) for permanent routes.The route command is deprecated in favor of ip route from the iproute2 package, which offers more features and a consistent syntax.The specified gateway must be reachable before adding a route through it; set up a direct route to the gateway first if necessary.Modifying routes requires root privileges. Incorrect routing configuration can cause complete loss of network connectivity.

SEE ALSO

ip(8), ip-route(8), ifconfig(8), netstat(8), traceroute(8)

Copied to clipboard
Kai