$OpenBSD: route.8,v 1.119 2023/08/02 23:34:13 aisha Exp $
$NetBSD: route.8,v 1.6 1995/03/18 15:00:13 cgd Exp $

Copyright (c) 1983, 1991, 1993
The Regents of the University of California. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

@(#)route.8 8.3 (Berkeley) 3/19/94

.Dd $Mdocdate: April 6 2023 $ .Dt ROUTE 8 .Os .Sh NAME .Nm route .Nd manually manipulate the routing tables .Sh SYNOPSIS .Nm route .Op Fl dnqtv .Op Fl T Ar rtable .Ar command .Oo .Op Ar modifier ... .Ar arg ... .Oc .Sh DESCRIPTION At system start, routing tables are initialised and configured by .Xr netstart 8 . The .Nm utility can be used to view or manually manipulate the network routing tables. Only the superuser may modify the routing tables.

p The options are as follows: l -tag -width Ds t Fl d Run in debug-only mode, i.e. don't actually modify the routing table. t Fl 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. t Fl q Suppress all output. t Fl T Ar 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 .Xr id 1 . t Fl t Write routing messages to a fake device

a ( /dev/null ) instead of a real routing socket to test route manipulation. t Fl v Print additional details. .El

p The commands are as follows:

p l -tag -width "XXXX" -compact t Xo .Nm route .Op Fl dnqtv .Op Fl T Ar rtable .Tg .Cm add .Op Ar modifier .Ar destination .Ar gateway .Xc t Xo .Nm route .Op Fl dnqtv .Op Fl T Ar rtable .Tg .Cm change .Op Ar modifier .Ar destination .Ar gateway .Xc Add a new route, or modify an existing route, to the host or network at .Ar destination . .Ar gateway is the next-hop intermediary by which packets should be routed. See .Sx Address notation and interpretation for more information.

p A number of modifiers can be used with .Cm add and .Cm change , and as documented with the other commands:

p l -tag -width Ds -compact t Ar flags Various flags can be set on routes (viewable using .Cm show ) :

p l -tag -width -blackhole -compact t Fl blackhole silently discard packets t Fl cloning generates a new route on use t Fl iface destination is directly reachable t Fl llinfo validly translates address to link address t Fl mpath multiple gateways for a destination exist t Fl nostatic pretend route added by kernel or daemon t Fl proto1 sets protocol specific routing flag #1 t Fl proto2 sets protocol specific routing flag #2 t Fl reject emits an ICMP unreachable when matched t Fl static manually added route (default) .El

p The .Fl blackhole and .Fl reject flags require a .Ar gateway to the loopback interface, either 127.0.0.1 or ::1.

p t Oo Fl lock | Fl lockrest Oc Fl expire Ar n t Oo Fl lock | Fl lockrest Oc Fl mtu Ar 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 .Ar n is locked if preceded by .Fl lock ; if preceded by .Fl lockrest all following .Fl expire and .Fl mtu metrics are locked.

p t Fl host | net Interpret .Ar destination as a host or network, respectively.

p t Fl ifa Ar address t Fl ifp Ar ifname Where the destination and gateway are not sufficient to specify the route, these modifiers may be used to determine the interface address

q Fl ifa or name

q Fl ifp .

p t Fl label Ar label Associate the route with a .Ar label . Route labels can be used to attach arbitrary information to a route.

p t Fl 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 .Xr sysctl 8 variables .Va net.inet.ip.multipath and .Va 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.

p t Xo .Fl mplslabel in Ar label .Fl push Ns | Ns Fl pop Ns | Ns Fl swap .Op Fl out Ar label .Xc For MPLS routes, specify an ingress LSR to associate a particular label to an IPv4/IPv6 route. The MPLS traffic .Fl in and .Fl out modifiers are intended to identify the ingress label and, optionally, the outgoing one. Additionally, one of the following operations must be used: .Fl push , .Fl pop or .Fl swap . The route's gateway can be specified using the .Fl inet or .Fl inet6 modifier before the address.

p t Fl netmask Ar mask t Fl prefixlen Ar len Used to add subnet routes with the specified netmask. The netmask should be specified after the .Ar destination parameter. If no netmask is specified, an implicit one is used for the .Dv AF_INET family. The network mask can also be specified as a prefix length, but in that case one of either .Fl inet or .Fl inet6 must also be specified.

p t Fl priority Ar n Specifies a routing priority. If no priority is specified, the kernel will set a priority depending on the .Dv RTF_STATIC flag to either .Dv RTP_STATIC or .Dv RTP_DEFAULT . Note that priority 1 is reserved for kernel use. .El

p t Xo .Nm route .Op Fl dnqtv .Op Fl T Ar rtable .Tg delete .Tg .Cm del Ns Op Cm ete .Ar destination .Op Fl priority Ar n .Op Ar gateway .Xc Delete the route to .Ar destination . If multiple routes to the destination exist, a specific route must be selected by specifying the priority and/or a gateway.

p t Xo .Nm route .Op Fl T Ar rtable .Tg .Cm exec .Ar command .Op Ar arg ... .Xc Execute a command, forcing the process and its children to use the routing table and appropriate routing domain as specified with the .Fl T Ar rtable option.

p t Xo .Nm route .Op Fl nqv .Op Fl T Ar rtable .Tg .Cm flush .Op Ar family .Op Fl iface Ar ifname .Op Fl priority Ar n .Xc 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 .Fl iface or .Fl priority modifiers.

p t Xo k -words .Nm route .Op Fl nv .Op Fl T Ar rtable .Tg .Cm get .Ar destination .Op Fl priority Ar n .Op Ar gateway .Ek .Xc Display the route to .Ar destination . If multiple routes to the destination exist, a specific route may be selected by specifying the priority and/or a gateway.

p t Xo .Nm .Op Fl n .Op Fl T Ar rtable .Tg .Cm monitor .Op Ar family .Op Fl iface .Xc 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 .Fl T option, or interface specific messages (link state changes) using the .Fl iface modifier.

p t Xo c route .Op Fl dtv .Op Fl T Ar rtable .Tg .Cm nameserver .Ar interface .Op Ar address ... .Xc Broadcast a list of up to five nameserver address proposals to .Xr resolvd 8 , which is used to update the list of nameservers for the given interface in .Xr resolv.conf 5 . If no address is given, a request to remove the nameservers for the given interface is sent.

p t Xo .Nm route .Op Fl nv .Op Fl T Ar rtable .Tg .Cm show .Op Ar family .Op Fl gateway .Op Fl label Ar label .Op Fl priority Ar n .Xc Display the routing table.

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

p If .Fl label is specified, only routes with the specified label are shown.

p If .Fl priority is specified, only routes with the specified priority are shown. It may be specified by number or one of .Cm local , .Cm connected , .Cm static , .Cm ospf , .Cm rip , or .Cm bgp . If the priority is negative, then routes that do not match the numeric priority are shown.

p Within the output of .Cm show , the "Flags" column indicates what flags are set on the route. The mapping between letters and flags is: l -column "1" "RTF_BLACKHOLE" "Protocol specific routing flag #1." t Dv 1 Ta Dv RTF_PROTO1 Ta "Protocol specific routing flag #1." t Dv 2 Ta Dv RTF_PROTO2 Ta "Protocol specific routing flag #2." t Dv 3 Ta Dv RTF_PROTO3 Ta "Protocol specific routing flag #3." t Dv B Ta Dv RTF_BLACKHOLE Ta "Just discard packets." t Dv b Ta Dv RTF_BROADCAST Ta "Correspond to a local broadcast address." t Dv C Ta Dv RTF_CLONING Ta "Generate new routes on use." t Dv c Ta Dv RTF_CLONED Ta "Cloned routes (generated from RTF_CLONING)." t Dv D Ta Dv RTF_DYNAMIC Ta "Created dynamically (by redirect)." t Dv G Ta Dv RTF_GATEWAY Ta "Dest requires forwarding by intermediary." t Dv H Ta Dv RTF_HOST Ta "Host entry (net otherwise)." t Dv h Ta Dv RTF_CACHED Ta "Referenced by gateway route." t Dv L Ta Dv RTF_LLINFO Ta "Valid protocol to link address translation." t Dv l Ta Dv RTF_LOCAL Ta "Correspond to a local address." t Dv M Ta Dv RTF_MODIFIED Ta "Modified dynamically (by redirect)." t Dv m Ta Dv RTF_MULTICAST Ta "Correspond to a multicast address." t Dv n Ta Dv RTF_CONNECTED Ta "Interface route." t Dv P Ta Dv RTF_MPATH Ta "Multipath route." t Dv R Ta Dv RTF_REJECT Ta "Host or net unreachable." t Dv S Ta Dv RTF_STATIC Ta "Manually added." t Dv T Ta Dv RTF_MPLS Ta "MPLS route." t Dv U Ta Dv RTF_UP Ta "Route usable." .El

p t Xo c route .Op Fl T Ar rtable .Tg .Cm sourceaddr .Op Fl ifp Ar ifname | Ar address .Xc Set the preferred source address to .Ar address . The source address can be set to the address assigned to interface .Ar ifname if .Fl 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. .El .Ss 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:

p l -tag -width "-inet6XXX" -offset indent -compact t Fl inet IPv4 addresses; see .Xr ip 4 t Fl inet6 IPv6 addresses; see .Xr ip6 4 t Fl link hardware (link-level) addresses t Fl mpls MPLS addresses t Fl sa actual .Vt sockaddr data, in hexadecimal format .El

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

p l -bullet -compact t the .Fl net modifier is used t it is the word "default", equivalent to 0/0 or ::/0 t it is an address with a .Dq / Ns Em XX suffix, where .Em XX is the number of bits in the network portion of the address t it specifies the network portion either with .Fl netmask or .Fl prefixlen .El

p If .Ar destination is a valid IP address or host name, or the .Fl host modifier is used, it is assumed to be a route to a host.

p All symbolic names specified for a .Ar destination or .Ar gateway are looked up using .Xr gethostbyname 3 . .Sh FILES l -tag -width "/etc/mygate" -compact t Pa /etc/hosts host and network name database t Pa /etc/mygate default gateway address .El .Sh EXIT STATUS For commands other than .Cm exec , the .Nm utility exits 0 on success, and >0 if an error occurs.

p For the .Cm exec command the .Nm utility exits with the exit status of .Ar command if it could be invoked. Otherwise the .Nm utility exits with one of the following values: l -tag -width Ds t 1 An invalid command line option was passed to .Nm or setting the routing table failed. t 126 .Ar command was found but could not be invoked. t 127 .Ar command could not be found. .El .Sh EXAMPLES Show the current IPv4 routing tables, without attempting to print hostnames symbolically:

p .Dl $ route -n show -inet

p Add a static .Xr inet 4 route to the 192.168.5.0/24 network via the 192.168.0.1 gateway:

p .Dl # route add -inet 192.168.5.0/24 192.168.0.1

p Amend the .Xr inet 4 route to the 192.168.5.0/24 network to use the 192.168.0.2 gateway:

p .Dl # route change -inet 192.168.5.0/24 192.168.0.2

p Delete the .Xr inet 4 route to the 192.168.5.0/24 network:

p .Dl # route delete -inet 192.168.5.0/24

p Add a static .Xr 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:

p .Dl # route add -inet6 2001:db8:efef::1 -cloning -link -iface vio0 .Dl # route add -inet6 default 2001:db8:efef::1 .Sh DIAGNOSTICS l -diag t "%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 .Xr gethostbyname 3 ) , the gateway address is printed numerically as well as symbolically. t "%s %s done" When the .Cm flush command is specified, each routing table entry deleted is indicated with a message of this form. t "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. t "not in table" A .Cm delete operation was attempted for an entry which wasn't present in the tables. t "routing table overflow" An .Cm add operation was attempted, but the system was low on resources and was unable to allocate memory to create the new entry. .El .Sh SEE ALSO .Xr gethostbyname 3 , .Xr inet_net_pton 3 , .Xr inet_pton 3 , .Xr route 4 , .Xr rtable 4 , .Xr hosts 5 , .Xr mygate 5 , .Xr netstart 8 .Sh HISTORY The .Nm command appeared in x 4.2 . IPv6 support was added by WIDE/KAME project.

p The .Fl recvpipe , .Fl hopcount , .Fl sendpipe , .Fl ssthresh , .Fl rtt , and .Fl 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. .Sh BUGS Some uses of the .Fl ifa or .Fl ifp modifiers with the .Cm add command will incorrectly fail with a .Dq Network is unreachable message if there is no default route. See case .Dv RTM_ADD in .Fn route_output from

a sys/net/rtsock.c for details.