Get a route:
route [ -nqv ] get
[ -host | -net ] destination
[ [ -interface | -gateway ] gateway ]
Monitor routes:
route [ -n ] monitor
Description
The route command allows you to
manipulate the network routing tables.
Only root may use the route command.
route understands the following options:
-n
Prevents attempts to print host and network names symbolically
when reporting actions. This can speed up actions.
-q
Suppresses all output. This can speed up actions such as flushing routes.
-v
Displays additional details (verbose mode).
route accepts the following commands:
add
Add a route.
change
Change the parameters of a route, such as its metrics, whether it is
rejected, and whether it uses path MTU discovery.
delete
Delete a specific route.
flush
Remove all gateway entries from the routing tables.
get
Look up and display the route for a destination.
monitor
Continuously report any changes to the routing information base,
routing lookup misses, or suspected subnetwork partitioning.
destination specifies the destination host or network.
gateway
specifies the next-hop gateway to which packets should be addressed.
The destination and gateway can be
specified by IP addresses or names.
route looks up
all symbolic names specified for a destination or a
gateway using
gethostbyname(3N).
If this fails, it uses
getnetbyname(3N)
to interpret the name as that of a network.
For those destinations that do not require a unique routing
table entry, use default as the destination
parameter.
In the following example, gator is the hostname
of the gateway machine:
route add default gator
route accepts the following command modifiers.
Note that some modifiers only work with certain commands:
-cloning
Mark a route via an interface as suitable for cloning.
For example, this is used to derive new multicast routes
from the multicast address 224.
-gatewaygateway
Specify a gateway.
-hostdestination
Force destination to be interpreted as a host.
-interfacegateway
Specify that gateway is to be interpreted as
the address of an interface on this host
rather than as the address of a remote gateway.
The specified interface will be used as a route for transmission.
This modifier is equivalent to the old and deprecated
syntax of specifying ``0'' after gateway.
This option may also be specified as -iface.
-ifainterface_spec
Interpret interface_spec as an interface address.
This option is only needed when the destination and gateway are not sufficient
to identify the route for add or change commands.
-ifpinterface_spec
Interpret interface_spec as an interface name.
This option is only needed when the destination and gateway are not sufficient
to identify the route for add or change commands.
-inet
Flush only those routes whose destinations use
version 4 of the Internet protocol.
-lock -metricvalue
Lock the initial value of an individual metric option.
-lockrest
Lock the initial value of all metrics subsequently specified on the
command line.
-metricvalue
Provide initial values for metrics and other parameters
maintained in the routing entry.
Available -metric options are:
-expire
Specify the expiry time of the route in seconds.
An expiry time of 0 implies that the route will not expire.
-hopcount
Specify the number of hops.
-mtu
Specify the maximum transmission unit in bytes.
-recvpipe
Specify the bandwidth of the receive pipe in bytes.
-rtt
Specify the round-trip time in milliseconds.
-rttvar
Specify the variance in round-trip time in milliseconds.
-sendpipe
Specify the bandwidth of the send pipe in bytes.
-ssthresh
Specify the slow start threshold size in bytes.
-tos
Specify the type of service as defined in RFC 1349.
Note that most routing protocols only use or calculate
a subset of these metrics, and so route get
may display their values as 0.
For example, RIP uses the hop count metric.
Values may be locked by specifying -lock before the metric option.
-netdestination
Force destination to be interpreted as a network.
-netmasknew_mask
Override the implicit network mask with new_mask.
-nostatic
Pretend that route has been added by the kernel or a routing daemon.
-reject
Prevent network traffic from using this route.
-notreject
Allow network traffic to use this route.
-static
Mark route as having been added manually.
If one of the options -host or -net
is not specified, routes to a particular host are
distinguished from those to a network by interpreting the
IP address associated with destination.
If the destination has a ``local address
part'' of INADDR_ANY or if the
destination is the symbolic name of a network,
the route is assumed to be to a network; otherwise, it is
assumed to be a route to a host. This is demonstrated in the following
table:
Destination entry
Interpreted as
128.32
-host 128.0.0.32
-net 128.32
-net 128.32.0.0
128.32.130
-host 128.32.0.130
-net 128.32.130
-net 128.32.130.0
The kernel variables ipforwarding,
ipsendredirects, and ipnonlocalsrcroute
are relevant to systems set up as routers.
For more information about these variables, see
inconfig(1Mtcp).
Diagnostics
Error messages
network is unreachable
An attempt to add a route failed because the gateway listed
was not on a directly-connected network. The next-hop
gateway must be given.
not in table
A delete operation was attempted for an entry which wasn't
present in the tables.
routing table overflow
An add operation was attempted, but the system was low on
resources and was unable to allocate memory to create the
new entry.
Confirmation messages
add hostdestination:gatewaygatewayflagshex-flags
The specified route to a host 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 was not the primary address of the gateway
(that is, the first one returned by gethostbyname),
the gateway address is printed numerically as well as
symbolically.