route
View or manipulate the IP routing table
TLDR
Display the information of route table
Add route rule
Delete route rule
SYNOPSIS
route [options] [command] [destination] [parameters]
Common usage patterns:
route [-nNvee] [-FC] [<AFI>] [<destination>]
route [-V] [--version] [-h] [--help]
route add [-net|-host] <destination> [netmask <mask>] [gw <gateway>] [dev <interface>]
route del [-net|-host] <destination> [netmask <mask>] [gw <gateway>] [dev <interface>]
PARAMETERS
add
Adds a new route entry to the routing table.
del
Deletes an existing route entry from the routing table.
-n
Displays numerical addresses instead of trying to determine symbolic host names. This speeds up output.
-e
Displays more information in the output, such as the metric and window values.
-v
Enables verbose mode, providing more details about the command's execution.
-A
Specifies the Address Family Identifier (e.g., inet for IPv4, inet6 for IPv6) for the route operation. Defaults to inet if not specified.
-net
Indicates that the destination is a network address.
-host
Indicates that the destination is a host address.
The target IP address or network. This can be an IP address (e.g., 192.168.1.0), a network address in CIDR notation (e.g., 192.168.1.0/24), or a symbolic hostname.
netmask
Specifies the network mask for network routes. For example, 255.255.255.0.
gw
Specifies the IP address of the gateway through which packets for the destination should be routed.
dev
Specifies the outgoing network interface (e.g., eth0, enp0s3) to be used for the route.
metric
Sets the route cost metric, an integer value that influences route selection (lower metric is preferred). Used for administrative distance or cost.
reject
Adds a 'blackhole' route that drops packets destined for the specified target without sending an ICMP error.
DESCRIPTION
The route command is a utility used to view and manipulate the kernel's IP routing table. This table dictates how network packets are forwarded from your system to their destinations. When your system sends a packet, it consults the routing table to find the most efficient path to the destination IP address.
While route can be used for basic tasks like adding or deleting static routes and displaying the current routing configuration, it is considered a legacy tool. Modern Linux distributions increasingly favor the more powerful and flexible ip command (specifically, ip route) from the iproute2 suite for network configuration tasks, including routing. Despite its age, route remains available on many systems for backward compatibility and simpler routing operations.
CAVEATS
The route command is considered legacy in modern Linux distributions. It is part of the older net-tools package, which has largely been superseded by the iproute2 suite (containing the ip command). While still widely available, for new scripts and advanced network configurations, the ip command is generally preferred. Routes added with route are typically not persistent across reboots; they must be configured through system-specific network configuration files or scripts to remain active after a system restart.
DEPRECATION AND MODERN ALTERNATIVES
While route is still functional, the iproute2 tools, specifically the ip command, are the recommended modern alternative for managing network configurations on Linux. ip route provides more granular control, better support for IPv6, policy routing, and other advanced features that route lacks.
ROUTE PERSISTENCE
It's important to note that any routes added or deleted using the route command are temporary and will be lost upon system reboot. To make routing changes permanent, they must be configured within the system's network configuration files (e.g., /etc/network/interfaces on Debian/Ubuntu, /etc/sysconfig/network-scripts/route-* on RHEL/CentOS, or using NetworkManager) or through equivalent declarative network configuration tools.
HISTORY
The route command has been a staple utility in Unix-like operating systems for decades, originating from BSD Unix. It was part of the traditional net-tools collection, providing essential network configuration capabilities. Over time, as Linux networking became more complex, particularly with the advent of IPv6, policy routing, and multiple routing tables, the limitations of net-tools became apparent. This led to the development of the iproute2 suite, which offers a more robust and flexible framework for network management. Consequently, while route is still maintained for backward compatibility, its usage has declined in favor of the more modern ip route command.