NAME
route —
manually manipulate the routing
tables
SYNOPSIS
route |
[-dnqtv] [-T
rtable] command
[[modifier ...] arg ...] |
DESCRIPTION
At system start, routing tables are initialised and configured by
netstart(8). The route utility can be used to
view or manually manipulate the network routing tables. Only the superuser
may modify the routing tables.
The options are as follows:
-d- Run in debug-only mode, i.e. don't actually modify the routing table.
-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 consuming, and may require correct operation of the network; thus it may be expedient to forgo this, especially when attempting to repair networking operations.
-q- Suppress all output.
-Trtable- Select an alternate routing table to modify or query. The default is to use the current routing table. The current routing table can be displayed with id(1).
-t- Write routing messages to a fake device (/dev/null) instead of a real routing socket to test route manipulation.
-v- Print additional details.
The commands are as follows:
route[-dnqtv] [-Trtable]add[modifier] destination gatewayroute[-dnqtv] [-Trtable]change[modifier] destination gateway- Add a new route, or modify an existing route, to the host or network at
destination. gateway is the
next-hop intermediary by which packets should be routed. See
Address notation
and interpretation for more information.
A number of modifiers can be used with
addandchange, and as documented with the other commands:- flags
- Various flags can be set on routes (viewable using
show):-blackhole- silently discard packets
-cloning- generates a new route on use
-iface- destination is directly reachable
-llinfo- validly translates address to link address
-mpath- multiple gateways for a destination exist
-nostatic- pretend route added by kernel or daemon
-proto1- sets protocol specific routing flag #1
-proto2- sets protocol specific routing flag #2
-reject- emits an ICMP unreachable when matched
-static- manually added route (default)
The
-blackholeand-rejectflags require a gateway to the loopback interface, either 127.0.0.1 or ::1. - [
-lock|-lockrest]-expiren - [
-lock|-lockrest]-mtun - Specify the lifetime for the route (e.g. if generated by a redirect)
or the Maximum Transmission Unit (MTU) size for this path,
respectively. The value n is locked if preceded
by
-lock; if preceded by-lockrestall following-expireand-mtumetrics are locked. -host|-net- Interpret destination as a host or network, respectively.
-ifaaddress-ifpifname- Where the destination and gateway are not sufficient to specify the
route, these modifiers may be used to determine the interface address
(
-ifa) or name (-ifp). -labellabel- Associate the route with a label. Route labels can be used to attach arbitrary information to a route.
-mpath- Used to enter multiple gateways for the same destination address (multipath). When multiple routes exist for a destination, one route is selected based on the source address of the packet. The sysctl(8) variables net.inet.ip.multipath and net.inet6.ip6.multipath are used to control multipath routing. If set to 1, multiple routes with the same priority are used equally; if set to 0, the first route selected will be used for subsequent packets to that destination regardless of source.
-mplslabel-inlabel-push|-pop|-swap[-outlabel]- For MPLS routes, specify an ingress LSR to associate a particular
label to an IPv4/IPv6 route. The MPLS traffic
-inand-outmodifiers are intended to identify the ingress label and, optionally, the outgoing one. Additionally, one of the following operations must be used:-push,-popor-swap. The route's gateway can be specified using the-inetor-inet6modifier before the address. -netmaskmask-prefixlenlen- Used to add subnet routes with the specified netmask. The netmask
should be specified after the destination
parameter. If no netmask is specified, an implicit one is used for the
AF_INETfamily. The network mask can also be specified as a prefix length, but in that case one of either-inetor-inet6must also be specified. -priorityn- Specifies a routing priority. If no priority is specified, the kernel
will set a priority depending on the
RTF_STATICflag to eitherRTP_STATICorRTP_DEFAULT. Note that priority 1 is reserved for kernel use.
route[-dnqtv] [-Trtable]del[ete] destination [-priorityn] [gateway]- Delete the route to destination. If multiple routes to the destination exist, a specific route must be selected by specifying the priority and/or a gateway.
route[-Trtable]execcommand [arg ...]- Execute a command, forcing the process and its children to use the routing
table and appropriate routing domain as specified with the
-Trtable option. route[-nqv] [-Trtable]flush[family] [-ifaceifname] [-priorityn]- Delete all gateway entries from the routing table, optionally limited to a
specific address family. Routes matching a specific interface or priority
can be flushed by using the
-ifaceor-prioritymodifiers. route[-nv] [-Trtable]getdestination [-priorityn] [gateway]- Display the route to destination. If multiple routes to the destination exist, a specific route may be selected by specifying the priority and/or a gateway.
route[-n] [-Trtable]monitor[family] [-iface]- Continuously report any changes to the routing information base. The
information reported can be limited to a specific address family, a
specific routing table using the
-Toption, or interface specific messages (link state changes) using the-ifacemodifier. route[-dtv] [-Trtable]nameserverinterface [address ...]- Broadcast a list of up to five nameserver address proposals to resolvd(8), which is used to update the list of nameservers for the given interface in resolv.conf(5). If no address is given, a request to remove the nameservers for the given interface is sent.
route[-nv] [-Trtable]show[family] [-gateway] [-labellabel] [-priorityn]- Display the routing table.
If
-gatewayis specified, only routes whose gateway are in the same address family as the destination are shown.If
-labelis specified, only routes with the specified label are shown.If
-priorityis specified, only routes with the specified priority are shown. It may be specified by number or one oflocal,connected,static,ospf,rip, orbgp. If the priority is negative, then routes that do not match the numeric priority are shown.Within the output of
show, the "Flags" column indicates what flags are set on the route. The mapping between letters and flags is:1RTF_PROTO1Protocol specific routing flag #1. 2RTF_PROTO2Protocol specific routing flag #2. 3RTF_PROTO3Protocol specific routing flag #3. BRTF_BLACKHOLEJust discard packets. bRTF_BROADCASTCorrespond to a local broadcast address. CRTF_CLONINGGenerate new routes on use. cRTF_CLONEDCloned routes (generated from RTF_CLONING). DRTF_DYNAMICCreated dynamically (by redirect). GRTF_GATEWAYDest requires forwarding by intermediary. HRTF_HOSTHost entry (net otherwise). hRTF_CACHEDReferenced by gateway route. LRTF_LLINFOValid protocol to link address translation. lRTF_LOCALCorrespond to a local address. MRTF_MODIFIEDModified dynamically (by redirect). mRTF_MULTICASTCorrespond to a multicast address. nRTF_CONNECTEDInterface route. PRTF_MPATHMultipath route. RRTF_REJECTHost or net unreachable. SRTF_STATICManually added. TRTF_MPLSMPLS route. URTF_UPRoute usable. route[-Trtable]sourceaddr[-ifpifname | address]- Set the preferred source address to address. The
source address can be set to the address assigned to interface
ifname if
-ifpis specified, or reset by setting the address to zero. If no arguments are given, the preferred source addresses are printed. The preferred source address is not used if the destination is on-link or the source address is assigned to a disabled interface.
Address notation and interpretation
Addresses are assumed to be IPv4 unless they contain a colon, in which case they are treated as IPv6. Alternatively they may be specified as belonging to a particular address family using one of the following modifiers:
destination is assumed to be a route to a network if any of the following apply:
- the
-netmodifier is used - it is the word "default", equivalent to 0/0 or ::/0
- it is an address with a “/XX” suffix, where XX is the number of bits in the network portion of the address
- it specifies the network portion either with
-netmaskor-prefixlen
If destination is a valid IP address or host
name, or the -host modifier is used, it is assumed
to be a route to a host.
All symbolic names specified for a destination or gateway are looked up using gethostbyname(3).
FILES
- /etc/hosts
- host and network name database
- /etc/mygate
- default gateway address
EXIT STATUS
For commands other than exec, the
route utility exits 0 on success, and >0 if an
error occurs.
For the exec command the
route utility exits with the exit status of
command if it could be invoked. Otherwise the
route utility exits with one of the following
values:
- 1
- An invalid command line option was passed to
routeor setting the routing table failed. - 126
- command was found but could not be invoked.
- 127
- command could not be found.
EXAMPLES
Show the current IPv4 routing tables, without attempting to print hostnames symbolically:
$ route -n show -inetAdd a static inet(4) route to the 192.168.5.0/24 network via the 192.168.0.1 gateway:
# route add -inet 192.168.5.0/24
192.168.0.1Amend the inet(4) route to the 192.168.5.0/24 network to use the 192.168.0.2 gateway:
# route change -inet 192.168.5.0/24
192.168.0.2Delete the inet(4) route to the 192.168.5.0/24 network:
# route delete -inet
192.168.5.0/24Add a static inet6(4) route to a host which is on the vio0 interface that is outside your prefix, and use that host as a default gateway, as used by some hosting providers:
# route add -inet6 2001:db8:efef::1
-cloning -link -iface vio0# route add -inet6 default
2001:db8:efef::1DIAGNOSTICS
- %s: gateway %s flags %x
- The specified route is being added to or deleted from the tables. 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 symbolically.
- %s %s done
- When the
flushcommand 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 next-hop gateway must be given.
- not in table
- A
deleteoperation was attempted for an entry which wasn't present in the tables. - routing table overflow
- An
addoperation was attempted, but the system was low on resources and was unable to allocate memory to create the new entry.
SEE ALSO
gethostbyname(3), inet_net_pton(3), inet_pton(3), route(4), rtable(4), hosts(5), mygate(5), netstart(8)
HISTORY
The route command appeared in
4.2BSD. IPv6 support was added by WIDE/KAME
project.
The -recvpipe,
-hopcount, -sendpipe,
-ssthresh, -rtt, and
-rttvar modifiers used to be used to initialize
various quantities in routing table entries. The routing system no longer
uses these values and the modifiers exist now only for compatibility with
other operating systems.
BUGS
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 route_output()
from sys/net/rtsock.c for details.