ROUTE(8) | System Manager's Manual | ROUTE(8)

# 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.
`-T` rtable
  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`] [`-T` rtable] `add` [modifier] destination gateway
`route` [`-dnqtv`] [`-T` rtable] `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 `add` and `change`, 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 `-blackhole` and `-reject` flags require a gateway to the loopback interface, either 127.0.0.1 or ::1.

  [`-lock` | `-lockrest`] `-expire` n
  [`-lock` | `-lockrest`] `-mtu` n
    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 `-lockrest` all following `-expire` and `-mtu` metrics are locked.

  `-host` | `-net`
    Interpret destination as a host or network, respectively.

  `-ifa` address
  `-ifp` ifname
    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`).

  `-label` label
    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` `-in` label `-push`|`-pop`|`-swap` [`-out` label]
    For MPLS routes, specify an ingress LSR to associate a particular label to an IPv4/IPv6 route. The MPLS traffic `-in` and `-out` modifiers are intended to identify the ingress label and, optionally, the outgoing one. Additionally, one of the following operations must be used: `-push`, `-pop` or `-swap`. The route's gateway can be specified using the `-inet` or `-inet6` modifier before the address.

  `-netmask` mask
  `-prefixlen` len
    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_INET` family. The network mask can also be specified as a prefix length, but in that case one of either `-inet` or `-inet6` must also be specified.

  `-priority` n
    Specifies a routing priority. If no priority is specified, the kernel will set a priority depending on the `RTF_STATIC` flag to either `RTP_STATIC` or `RTP_DEFAULT`. Note that priority 1 is reserved for kernel use.

`route` [`-dnqtv`] [`-T` rtable] `del`[`ete`] destination [`-priority` n] [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` [`-T` rtable] `exec` command [arg ...]
  Execute a command, forcing the process and its children to use the routing table and appropriate routing domain as specified with the `-T` rtable option.

`route` [`-nqv`] [`-T` rtable] `flush` [family] [`-iface` ifname] [`-priority` n]
  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 `-iface` or `-priority` modifiers.

`route` [`-nv`] [`-T` rtable] `get` destination [`-priority` n] [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`] [`-T` rtable] `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 `-T` option, or interface specific messages (link state changes) using the `-iface` modifier.

`route` [`-dtv`] [`-T` rtable] `nameserver` interface [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`] [`-T` rtable] `show` [family] [`-gateway`] [`-label` label] [`-priority` n]
  Display the routing table.

  If `-gateway` is specified, only routes whose gateway are in the same address family as the destination are shown.

  If `-label` is specified, only routes with the specified label are shown.

  If `-priority` is specified, only routes with the specified priority are shown. It may be specified by number or one of `local`, `connected`, `static`, `ospf`, `rip`, or `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:

  `1` | `RTF_PROTO1` | Protocol specific routing flag #1.
  `2` | `RTF_PROTO2` | Protocol specific routing flag #2.
  `3` | `RTF_PROTO3` | Protocol specific routing flag #3.
  `B` | `RTF_BLACKHOLE` | Just discard packets.
  `b` | `RTF_BROADCAST` | Correspond to a local broadcast address.
  `C` | `RTF_CLONING` | Generate new routes on use.
  `c` | `RTF_CLONED` | Cloned routes (generated from RTF_CLONING).
  `D` | `RTF_DYNAMIC` | Created dynamically (by redirect).
  `G` | `RTF_GATEWAY` | Dest requires forwarding by intermediary.
  `H` | `RTF_HOST` | Host entry (net otherwise).
  `h` | `RTF_CACHED` | Referenced by gateway route.
  `L` | `RTF_LLINFO` | Valid protocol to link address translation.
  `l` | `RTF_LOCAL` | Correspond to a local address.
  `M` | `RTF_MODIFIED` | Modified dynamically (by redirect).
  `m` | `RTF_MULTICAST` | Correspond to a multicast address.
  `n` | `RTF_CONNECTED` | Interface route.
  `P` | `RTF_MPATH` | Multipath route.
  `R` | `RTF_REJECT` | Host or net unreachable.
  `S` | `RTF_STATIC` | Manually added.
  `T` | `RTF_MPLS` | MPLS route.
  `U` | `RTF_UP` | Route usable.

`route` [`-T` rtable] `sourceaddr` [`-ifp` ifname | address]
  Set the preferred source address to address. The source address can be set to the address assigned to interface ifname if `-ifp` is 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:

`-inet`
  IPv4 addresses; see ip(4)
`-inet6`
  IPv6 addresses; see ip6(4)
`-link`
  hardware (link-level) addresses
`-mpls`
  MPLS addresses
`-sa`
  actual sockaddr data, in hexadecimal format

destination is assumed to be a route to a network if any of the following apply:

- the `-net` modifier 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 `-netmask` or `-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 `route` or 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 -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`

# DIAGNOSTICS

%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 `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 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.

# 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.

August 2, 2023 | Debian