| ROUTE(8) | System Manager's Manual | ROUTE(8) |
route — manually
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:
-d-n-q-T
rtable-t-vThe commands are as follows:
route [-dnqtv]
[-T rtable]
add
[modifier] destination
gatewayroute [-dnqtv]
[-T rtable]
change
[modifier] destination
gatewayA number of modifiers can be used with
add and change, and as
documented with the other commands:
show):
-blackhole-cloning-iface-llinfo-mpath-nostatic-proto1-proto2-reject-staticThe -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-lock; if preceded by
-lockrest all following
-expire and -mtu
metrics are locked.
-host
|
-net-ifa
address-ifp
ifname-ifa) or name (-ifp).
-label
label-mpath-mplslabel
-in label
-push|-pop|-swap
[-out label]-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
lenAF_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
nRTF_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]route [-T
rtable]
exec
command [arg ...]-T rtable option.
route [-nqv]
[-T rtable]
flush
[family] [-iface
ifname] [-priority
n]-iface or
-priority modifiers.
route [-nv]
[-T rtable] get
destination
[-priority n]
[gateway]route [-n]
[-T rtable]
monitor
[family] [-iface]-T option, or
interface specific messages (link state changes) using the
-iface modifier.
route
[-dtv] [-T
rtable]
nameserver
interface [address ...]route [-nv]
[-T rtable]
show
[family] [-gateway]
[-label label]
[-priority n]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]-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:
destination is assumed to be a route to a network if any of the following apply:
-net modifier is used-netmask or
-prefixlenIf 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).
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:
route
or setting the routing table failed.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::1flush command is specified, each routing
table entry deleted is indicated with a message of this form.delete operation was attempted for an entry
which wasn't present in the tables.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.
| August 2, 2023 | openbsd |