manually manipulate the routing
At system start, routing tables are initialised and configured by
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:
- Run in debug-only mode, i.e. don't actually modify the routing table.
- 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.
- Suppress all output.
- 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).
- Write routing messages to a fake device (/dev/null) instead of a real routing socket to test route manipulation.
- Print additional details.
The commands are as follows:
add[modifier] destination gateway
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
and interpretation for more information.
A number of modifiers can be used with
change, and as documented with the other commands:
- Various flags can be set on routes (viewable using
- silently discard packets
- generates a new route on use
- destination is directly reachable
- validly translates address to link address
- multiple gateways for a destination exist
- pretend route added by kernel or daemon
- sets protocol specific routing flag #1
- sets protocol specific routing flag #2
- emits an ICMP unreachable when matched
- manually added route (default)
-rejectflags require a gateway to the loopback interface, either 127.0.0.1 or ::1.
- 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
-lock; if preceded by
-mtumetrics are locked.
- Interpret destination as a host or network, respectively.
- 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 (
- Associate the route with a label. Route labels can be used to attach arbitrary information to a route.
- 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.
- For MPLS routes, specify an ingress LSR to associate a particular
label to an IPv4/IPv6 route. The MPLS traffic
-outmodifiers are intended to identify the ingress label and, optionally, the outgoing one. Additionally, one of the following operations must be used:
-swap. The route's gateway can be specified using the
-inet6modifier before the address.
- 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
-inet6must also be specified.
- Specifies a routing priority. If no priority is specified, the kernel
will set a priority depending on the
RTF_STATICflag to either
RTP_DEFAULT. Note that priority 1 is reserved for kernel use.
ete] destination [
- 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.
- Execute a command, forcing the process and its children to use the routing
table and appropriate routing domain as specified with the
- 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
- 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.
- 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
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.
- Display the routing table.
-gatewayis specified, only routes whose gateway are in the same address family as the destination are shown.
-labelis specified, only routes with the specified label are shown.
-priorityis specified, only routes with the specified priority are shown. It may be specified by number or one of
bgp. 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:
Protocol specific routing flag #1.
Protocol specific routing flag #2.
Protocol specific routing flag #3.
Just discard packets.
Correspond to a local broadcast address.
Generate new routes on use.
Cloned routes (generated from RTF_CLONING).
Created dynamically (by redirect).
Dest requires forwarding by intermediary.
Host entry (net otherwise).
Referenced by gateway route.
Valid protocol to link address translation.
Correspond to a local address.
Modified dynamically (by redirect).
Correspond to a multicast address.
Host or net unreachable.
-ifpifname | address]
- Set the preferred source address to address. The
source address can be set to the address assigned to interface
-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:
-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
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).
- host and network name database
- default gateway address
Show the current IPv4 routing tables, without attempting to print hostnames symbolically:
$ route -n show -inet
Add 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.1
Amend 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.2
Delete the inet(4) route to the 192.168.5.0/24 network:
# route delete -inet 192.168.5.0/24
Add 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::1
- %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
deleteoperation was attempted for an entry which wasn't present in the tables.
- routing table overflow
addoperation was attempted, but the system was low on resources and was unable to allocate memory to create the new entry.
gethostbyname(3), inet_net_pton(3), inet_pton(3), route(4), rtable(4), hosts(5), mygate(5), netstart(8)
route command appeared in
4.2BSD. IPv6 support was added by WIDE/KAME
-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.
Some uses of the
-ifp modifiers with the
command will incorrectly fail with a “Network is unreachable”
message if there is no default route. See case
from sys/net/rtsock.c for details.