route

manually manipulate the routing tables

Syntax:

route [-n] [-q] [-v] command [[modifiers] args]

Options:

-n
Don't print host and network names symbolically when reporting actions.
-q
Be quiet: suppress all output.
-v
Be verbose: print additional details.

Description:

You use the route utility to manually manipulate the network routing tables. Because the routing tables are usually taken care of by the routed daemon, you rarely need to use this utility.

The utility accepts the following commands:

add
Add a route.
flush
Flush the routing tables of all gateway entries.
delete
Delete a specific route.
change
Change aspects of a route (such as its gateway).
get
Look up and display the route for a destination.
monitor
Continuously report routing lookup misses, suspected network partitionings, or any changes to the routing information base.

The monitor command has the syntax:

route [-n] monitor

The flush command has the syntax:

route [-n] flush

The other commands have the syntax:

route [-n] command [-net|-host] destination gateway

where:

destination
the destination host or network
gateway
the next-hop gateway that packets should be addressed to

Routes to a particular host are distinguished from those to a network by interpreting the Internet address associated with destination. Specifying the optional keywords -net and -host force the destination to be interpreted as a network or a host, respectively.

If the destination has a “local address part” of INADDR_ANY, or if the destination is the symbolic name of a network, then the route is assumed to be to a network; otherwise, the route is assumed to be to a host. For example:

This destination:is interpreted as:
128.32-host 128.0.0.32
128.32.130-host 128.32.0.130
-net 128.32128.32.0.0
-net 128.32.130128.32.130.0.

If the route is via an interface rather than via a gateway, you should specify the -interface modifier; the gateway given is the address of this host on the common network, indicating the interface to be used for transmission.

The optional -netmask modifier can be used to specify an additional address parameter that will interpreted as a network mask. The implicit network mask generated in the inet case can be overridden by placing this option after the destination parameter.

The optional modifiers:

provide initial values to metrics maintained in the routing entry. To lock any of these modifiers, precede the modifier with the -lock meta-modifier; you can also specify the -lockrest meta-modifier to lock all ensuing metrics.

All symbolic names specified for a destination or gateway are looked up first as a hostname using gethostname(). If this lookup fails, getnetname() is then used to interpret the name as that of a network.

The route utility uses a routing socket and the new message types RTM_ADD, RTM_DELETE, RTM_GET, and RTM_CHANGE. As such, only the superuser may modify the routing tables.

Diagnostics:

Error Message:Meaning:
add [host | network ] %s: gateway %s flags %xThe specified route is being added to the tables. The values printed are from the routing table entry supplied in the ioctl() call. If the gateway address used isn't the primary address of the gateway — the first one returned by gethostname() — the gateway address is printed numerically as well as symbolically.
delete [ host &| network ] %s: gateway %s flags %xAs above, but when deleting an entry.
%s %s doneA routing table entry is being deleted by the flush command.
Network is unreachableAn attempt to add a route failed because the gateway listed wasn't on a directly connected network. The next-hop gateway must be given.
not in tableA delete operation was attempted for an entry not present in the tables.
routing table overflowAn add operation was attempted, but the system was low on resources and couldn't allocate memory to create the new entry.

See also:

gated, routed