OpenBSD manual page server

Manual Page Search Parameters

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

routemanually manipulate the routing tables

route [-dnqtv] [-T rtable] command [[modifier ...] arg ...]

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:

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.
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).
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:

route [-dnqtv] [-T rtable] [modifier] destination gateway
 
route [-dnqtv] [-T rtable] [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):

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)

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.

|
Interpret destination as a host or network, respectively.

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

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

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

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] [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] [command ...]
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] [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 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] [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.

[-dtv] [-T rtable] 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] [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 Protocol specific routing flag #1.
2 Protocol specific routing flag #2.
3 Protocol specific routing flag #3.
B Just discard packets.
b Correspond to a local broadcast address.
C Generate new routes on use.
c Cloned routes (generated from RTF_CLONING).
D Created dynamically (by redirect).
G Dest requires forwarding by intermediary.
H Host entry (net otherwise).
h Referenced by gateway route.
L Valid protocol to link address translation.
l Correspond to a local address.
M Modified dynamically (by redirect).
m Correspond to a multicast address.
n Interface route.
P Multipath route.
R Host or net unreachable.
S Manually added.
T MPLS route.
U Route usable.

[-T rtable] [-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.

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:

IPv4 addresses; see ip(4)
IPv6 addresses; see ip6(4)
hardware (link-level) addresses
MPLS addresses
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).

/etc/hosts
host and network name database
/etc/mygate
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 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.

gethostbyname(3), inet_net_pton(3), inet_pton(3), route(4), rtable(4), hosts(5), mygate(5), netstart(8)

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.

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.

March 18, 2023 OpenBSD-7.3