route - manually manipulate the routing tables
route [-dnqtv] command [[modifiers] args]
route is a utility used to manually view and manipulate the
tables. Except for setting up the default route, it
normally is not
needed to manipulate routes, as a system routing table management daemon,
such as routed(8) or bgpd(8), should tend to this task.
route can be used to modify nearly any aspect of the routing
packet forwarding, which can be manipulated through the
The route utility supports a limited number of general options, but a
rich command language enables the user to specify any arbitrary request
that could be delivered via the programmatic interface discussed in
The options are as follows:
-d Run in debug-only mode, i.e., don't actually modify
-n Bypass attempts to print host and network names symbolically when
reporting actions. (The process of translating between symbolic
names and numerical equivalents can be quite time
may require correct operation of the network; thus
it may be expedient
to forgo this, especially when attempting to
-q Suppress all output.
-t Write routing messages to a fake device (/dev/null)
instead of a
real routing socket to test route manipulation.
-v (verbose) Print additional details.
The route utility provides several commands:
add Add a route.
change Change aspects of a route (such as its gateway).
delete Delete a specific route.
flush Remove all routes.
get Lookup and display the route for a destination.
monitor Continuously report any changes to the routing
base, routing lookup misses, or suspected network partitionings.
show Print out the route table similar to "netstat
The get command has the syntax:
route [-nv] get [modifiers] address
The flush command has the syntax:
route [-dnqtv] flush [family]
If the flush command is specified, route will ``flush'' the
of all gateway entries. When the address family is
specified by any
one of the family modifiers (listed below), only routes having destinations
with addresses in the delineated family will be deleted.
The monitor command has the syntax:
route [-dn] monitor
The show command has the syntax:
route [-n] show [family]
The other commands have the syntax:
route [-dnqtv] command [modifiers] destination gateway
destination is the destination host or network, gateway is
intermediary via which packets should be routed, and netmask
same as the argument to the -netmask modifier and is described below.
Routes to a particular host may be distinguished from those
to a network
by interpreting the Internet address specified as the
The optional modifiers -net and -host cause the destination to be
interpreted as a network or a host, respectively. Otherwise, type is
chosen based on the following rules:
The route is assumed to be to a network if any of the following apply to
+o it is the word "default", equivalent to 0/0
+o it is an IPv4 address with less than 3 dots
+o it is an IPv4 address with a ``/XX'' suffix (where XX is
of bits in the network portion of the address and is
less than 32)
+o it is the symbolic name of a network.
If destination is a valid IP address or host name, it is
presumed to be a
route to a host.
If none of the above apply, route prints an error message
For example, 192.168.1.1 is interpreted as -host 192.168.1.1
192.168.1 is interpreted as -net 192.168.1. Note, however,
192.168.2.0 will be interpreted as -host 192.168.2.0 since
it is a complete
IP address with 3 dots. In this case the number of
bits in the
network portion of the address must be explicitly listed,
192.168.2.0/24, 192.168.2/24, or alternately 192.168.2.
If the destination is directly reachable via an interface
intermediary system to act as a gateway, the -interface modifier should
be specified; the gateway given is the address of this host
on the common
network, indicating the interface to be used for transmission.
To allow addresses to be interpreted as belonging to a particular address
family (as well as for use in the family arguments to some
following modifiers may be used:
-inet Internet Protocol version 4 (IPv4) addresses (see
-inet6 Internet Protocol version 6 (IPv6) addresses (see
-ipx Novell's Internet Packet Exchange (IPX) addresses
-link Hardware (link-level) addresses
-sa Actual sockaddr data, in hexadecimal format
-x25 CCITT X.25 addresses
The optional modifier -link specifies that all subsequent
specified as link-level addresses, and the names must be numeric specifications
rather than symbolic names.
The optional -netmask qualifier is intended to manually add
with netmasks different from that of the implied network interface (as
would otherwise be communicated using a routing protocol).
an additional ensuing address parameter (to be interpreted
as a network
mask). The implicit network mask generated in the AF_INET
case can be
overridden by making sure this option follows the
-prefixlen is also available for a similar purpose, for
The optional -mpath modifier needs to be specified with the
to be able to enter multiple gateways for the same destination address
Routes have associated flags which influence operation of
when sending to destinations matched by the routes. These
flags may be
set (or sometimes cleared) by indicating the following corresponding modifiers:
-blackhole RTF_BLACKHOLE silently discard pkts (during
-cloning RTF_CLONING generates a new route on use
-iface ~RTF_GATEWAY destination is directly reachable
-llinfo RTF_LLINFO validly translates proto addr
to link addr
-mpath RTF_MPATH multiple gateways for a destination exist
-nostatic ~RTF_STATIC pretend route added by kernel
-proto1 RTF_PROTO1 set protocol specific routing
-proto2 RTF_PROTO2 set protocol specific routing
-reject RTF_REJECT emit an ICMP unreachable when
-static RTF_STATIC manually added route
-xresolve RTF_XRESOLVE emit mesg on use (for external
The optional modifiers -mtu and -expire provide initial values to quantities
maintained in the routing entry by transport level protocols, such
as TCP (see tcp(4)). They have the following meanings:
-expire n Lifetime for route (e.g., if generated by a
-mtu n Maximum transmission unit (MTU) size for this
These may be individually locked by preceding each such modifier to be
locked by the -lock meta-modifier, or one can specify that
metrics may be locked by the -lockrest meta-modifier.
In a change or add command where the destination and gateway
are not sufficient
to specify the route, the -ifp or -ifa modifiers may
be used to
determine the interface or interface address.
The optional -genmask modifier specifies that a cloning mask
This specifies the mask applied when determining if a child
be created. It is only applicable to network routes with
The optional -label modifier specifies on route addition or
that the route should have the given label associated with
it. Route labels
can be used to attach arbitrary information to a route.
All symbolic names specified for a destination or gateway
are looked up
first as a network name using getnetbyname(3). If this
gethostbyname(3) is then used to interpret the name as a
valid host name.
route uses a routing socket (see route(4)) and the message
RTM_DELETE, RTM_GET, and RTM_CHANGE. As such, only the superuser may
modify the routing tables.
/etc/hosts host name database
/etc/mygate default gateway address
/etc/networks network name database
%s: gateway %s flags %x The specified route is being added
to or deleted
from the tables. The values printed are from the routing
supplied in the ioctl(2) call. If the gateway address used
was not the
primary address of the gateway (the first one returned by
gethostbyname(3)), the gateway address is printed numerically as well as
%s %s done When the flush command is specified, each routing table entry
deleted is indicated with a message of this form.
Network is unreachable An attempt to add a route failed because the
gateway listed was not on a directly connected network. The
gateway must be given.
not in table A delete operation was attempted for an entry
present in the tables.
routing table overflow An add operation was attempted, but
was low on resources and was unable to allocate memory to
create the new
netstat(1), gethostbyname(3), getnetbyname(3), netintro(4),
tcp(4), hosts(5), mygate(5), networks(5), bgpd(8), routed(8), sysctl(8)
The route command appeared in 4.2BSD. IPv6 support was
The -recvpipe, -hopcount, -sendpipe, -ssthres, -rtt, and
used to be used to initialize various quantities in
entries. The routing system no longer uses these values and
exist now only for compatibility with other operating
The first paragraph may have slightly exaggerated routed(8)'s abilities.
Some uses of the -ifa or -ifp modifiers with the add command
fail with a ``Network is unreachable'' message if
there is no default
route. See case RTM_ADD in route_output() from
OpenBSD 3.6 March 19, 1994
[ Back ]