route can be used to modify nearly any aspect of the routing policy, except packet forwarding, which can be manipulated through the sysctl(8) command.
The route utility supports a limited number of general options, but a rich command language, enabling the user to specify any arbitrary request that could be delivered via the programmatic interface discussed in route(4).
The route utility provides several commands:
The monitor command has the syntax
route [-n] monitor
The flush command has the syntax
route [-n] flush [family]
If the flush command is specified, route will ``flush'' the routing tables of all gateway entries. When the address family is specified by any of the -osi, -xns, -atalk, -inet, or -inet6 modifiers, only routes having destinations with addresses in the delineated family will be manipulated.
The other commands have the following syntax:
route [-n] command [-net | -host] destination gateway
where
destination
is the destination host or network, and
gateway
is the next-hop intermediary via which packets should be routed.
Routes to a particular host may be distinguished from those to
a network by interpreting the Internet address specified as the
destination
argument.
The optional modifiers
-net
and
-host
force the destination to be interpreted as a network or a host, respectively.
Otherwise, 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, it is presumed to be a
route to a host.
Optionally, the
destination
can also be specified in the
net/bits
format.
For example,
128.32
is interpreted as
-host 128.0.0.32
;
128.32.130
is interpreted as
-host 128.32.0.130
;
-net 128.32
is interpreted as
128.32.0.0
;
and
-net 128.32.130
is interpreted as
128.32.130.0
.
The keyword default can be used as the destination to set up a default route to a smart gateway. If no other routes match, this default route will be used as a last resort.
If the destination is directly reachable via an interface requiring no 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.
The optional modifiers -xns, -osi, -atalk, and -link specify that all subsequent addresses are in the XNS, OSI, or AppleTalk address families, or are specified as link-level addresses, and the names must be numeric specifications rather than symbolic names.
The optional
-netmask
qualifier is intended
to achieve the effect of an
OSI
ESIS
redirect with the netmask option,
or to manually add subnet routes with
netmasks different from that of the implied network interface
(as would otherwise be communicated using the OSPF or ISIS routing protocols).
One specifies 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 destination parameter.
-prefixlen
is also available for similar purpose, in IPv4 and IPv6 case.
Routes have associated flags which influence operation of the protocols
when sending to destinations matched by the routes.
These flags may be set (or sometimes cleared)
by indicating the following corresponding modifiers:
-cloning RTF_CLONING - generates a new route on use
-nocloning ~RTF_CLONING - stop generating new routes on use
-cloned RTF_CLONED - cloned route generated by RTF_CLONING
-nocloned ~RTF_CLONED - prevent removal with RTF_CLONING parent
-xresolve RTF_XRESOLVE - emit mesg on use (for external lookup)
-iface ~RTF_GATEWAY - destination is directly reachable
-static RTF_STATIC - manually added route
-nostatic ~RTF_STATIC - pretend route added by kernel or daemon
-reject RTF_REJECT - emit an ICMP unreachable when matched
-blackhole RTF_BLACKHOLE - silently discard pkts (during updates)
-proto1 RTF_PROTO1 - set protocol specific routing flag #1
-proto2 RTF_PROTO2 - set protocol specific routing flag #2
-llinfo RTF_LLINFO - validly translates proto addr to link addr
The optional modifiers -rtt, -rttvar, -sendpipe, -recvpipe, -mtu, -hopcount, -expire, and -ssthresh provide initial values to quantities maintained in the routing entry by transport level protocols, such as TCP or TP4. These may be individually locked by preceding each such modifier to be locked by the -lock meta-modifier, or one can specify that all ensuing 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 (as in the ISO case where several interfaces may have the same address), the -ifp or -ifa modifiers may be used to determine the interface or interface address.
All symbolic names specified for a destination or gateway are looked up first as a host name using gethostbyname(3). If this lookup fails, getnetbyname(3) is then used to interpret the name as that of a network.
route
uses a routing socket and the new message types
RTM_ADD
,
RTM_DELETE
,
RTM_GET
,
and
RTM_CHANGE
.
As such, only the super-user may modify
the routing tables.
route
add
default
192.168.0.1
route
-n
show
route
add
-net
192.168.1.0
-netmask
255.255.255.240
10.200.0.1
Some uses of the
-ifa
or
-ifp
modifiers with the add command will incorrectly fail with a
``Network is unreachable''
message if there is no default route.
See case
RTM_ADD
in
sys/net/rtsock.c:route_output
for details.