xref: /freebsd/sbin/route/route.8 (revision 5e3190f700637fcfc1a52daeaa4a031fdd2557c7)
1.\" Copyright (c) 1983, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.\"     @(#)route.8	8.3 (Berkeley) 3/19/94
29.\"
30.Dd June 16, 2023
31.Dt ROUTE 8
32.Os
33.Sh NAME
34.Nm route
35.Nd manually manipulate the routing tables
36.Sh SYNOPSIS
37.Nm
38.Op Fl j Ar jail
39.Op Fl dnqtv
40.Ar command
41.Oo
42.Op Ar modifiers
43.Ar args
44.Oc
45.Sh DESCRIPTION
46The
47.Nm
48utility is used to manually manipulate the network
49routing tables.
50It normally is not needed, as a
51system routing table management daemon, such as
52.Xr routed 8 ,
53should tend to this task.
54.Pp
55The
56.Nm
57utility supports a limited number of general options,
58but a rich command language, enabling the user to specify
59any arbitrary request that could be delivered via the
60programmatic interface discussed in
61.Xr route 4 .
62.Pp
63The following options are available:
64.Bl -tag -width indent
65.It Fl 4
66Specify
67.Cm inet
68address family as family hint for subcommands.
69.It Fl 6
70Specify
71.Cm inet6
72address family as family hint for subcommands.
73.It Fl d
74Run in debug-only mode, i.e., do not actually modify the routing table.
75.It Fl n
76Bypass attempts to print host and network names symbolically
77when reporting actions.
78(The process of translating between symbolic
79names and numerical equivalents can be quite time consuming, and
80may require correct operation of the network; thus it may be expedient
81to forget this, especially when attempting to repair networking operations).
82.It Fl t
83Run in test-only mode.
84.Pa /dev/null
85is used instead of a socket.
86.It Fl v
87(verbose) Print additional details.
88.It Fl q
89Suppress all output from the
90.Cm add , change , delete ,
91and
92.Cm flush
93commands.
94.It Fl j Ar jail
95Run inside a jail.
96.El
97.Pp
98The
99.Nm
100utility provides the following commands:
101.Pp
102.Bl -tag -width Fl -compact
103.It Cm add
104Add a route.
105.It Cm flush
106Remove all routes.
107.It Cm delete
108Delete a specific route.
109.It Cm del
110Another name for the
111.Cm delete
112command.
113.It Cm change
114Change aspects of a route (such as its gateway).
115.It Cm get
116Lookup and display the route for a destination.
117.It Cm monitor
118Continuously report any changes to the routing information base,
119routing lookup misses, or suspected network partitionings.
120.It Cm show
121Another name for the
122.Cm get
123command.
124.El
125.Pp
126The monitor command has the syntax:
127.Pp
128.Bd -ragged -offset indent -compact
129.Nm
130.Op Fl n
131.Cm monitor Op Fl fib Ar number
132.Ed
133.Pp
134The flush command has the syntax:
135.Pp
136.Bd -ragged -offset indent -compact
137.Nm
138.Op Fl n
139.Cm flush Oo Ar family Oc Op Fl fib Ar number
140.Ed
141.Pp
142If the
143.Cm flush
144command is specified,
145.Nm
146will ``flush'' the routing tables of all gateway entries.
147When the address family may is specified by any of the
148.Fl inet6 ,
149or
150.Fl inet
151modifiers, only routes having destinations with addresses in the
152delineated family will be deleted.
153Additionally,
154.Fl 4
155or
156.Fl 6
157can be used as aliases for
158.Fl inet
159and
160.Fl inet6
161modifiers.
162When a
163.Fl fib
164option is specified, the operation will be applied to
165the specified FIB
166.Pq routing table .
167.Pp
168The add command has the following syntax:
169.Pp
170.Bd -ragged -offset indent -compact
171.Nm
172.Op Fl n
173.Cm add
174.Op Fl net No \&| Fl host
175.Ar destination gateway
176.Op Ar netmask
177.Op Fl fib Ar number
178.Ed
179.Pp
180and the other commands have the following syntax:
181.Pp
182.Bd -ragged -offset indent -compact
183.Nm
184.Op Fl n
185.Ar command
186.Op Fl net No \&| Fl host
187.Ar destination
188.Op Ar gateway Op Ar netmask
189.Op Fl fib Ar number
190.Ed
191.Pp
192where
193.Ar destination
194is the destination host or network,
195.Ar gateway
196is the next-hop intermediary via which packets should be routed.
197Routes to a particular host may be distinguished from those to
198a network by interpreting the Internet address specified as the
199.Ar destination
200argument.
201The optional modifiers
202.Fl net
203and
204.Fl host
205force the destination to be interpreted as a network or a host, respectively.
206Otherwise, if the
207.Ar destination
208has a
209.Dq local address part
210of
211INADDR_ANY
212.Pq Li 0.0.0.0 ,
213or if the
214.Ar destination
215is the symbolic name of a network, then the route is
216assumed to be to a network; otherwise, it is presumed to be a
217route to a host.
218Optionally, the
219.Ar destination
220could also be specified in the
221.Ar net Ns / Ns Ar bits
222format.
223.Pp
224For example,
225.Li 128.32
226is interpreted as
227.Fl host Li 128.0.0.32 ;
228.Li 128.32.130
229is interpreted as
230.Fl host Li 128.32.0.130 ;
231.Fl net Li 128.32
232is interpreted as
233.Li 128.32.0.0 ;
234.Fl net Li 128.32.130
235is interpreted as
236.Li 128.32.130.0 ;
237and
238.Li 192.168.64/20
239is interpreted as
240.Fl net Li 192.168.64 Fl netmask Li 255.255.240.0 .
241.Pp
242A
243.Ar destination
244of
245.Ar default
246is a synonym for the default route.
247For
248.Li IPv4
249it is
250.Fl net Fl inet Li 0.0.0.0 ,
251and for
252.Li IPv6
253it is
254.Fl net Fl inet6 Li :: .
255.Pp
256If the destination is directly reachable
257via an interface requiring
258no intermediary system to act as a gateway, the
259.Fl interface
260modifier should be specified;
261the gateway given is the address of this host on the common network,
262indicating the interface to be used for transmission.
263Alternately, if the interface is point to point the name of the interface
264itself may be given, in which case the route remains valid even
265if the local or remote addresses change.
266.Pp
267The optional
268.Fl netmask
269modifier is intended
270to achieve the effect of an OSI ESIS
271redirect with the netmask option,
272or to manually add subnet routes with
273netmasks different from that of the implied network interface
274(as would otherwise be communicated using the OSPF or ISIS routing protocols).
275One specifies an additional ensuing address parameter
276(to be interpreted as a network mask).
277The implicit network mask generated in the AF_INET case
278can be overridden by making sure this option follows the destination parameter.
279.Pp
280For
281.Dv AF_INET6 ,
282the
283.Fl prefixlen
284qualifier
285is available instead of the
286.Fl mask
287qualifier because non-continuous masks are not allowed in IPv6.
288For example,
289.Fl prefixlen Li 32
290specifies that a network mask of
291.Li ffff:ffff:0000:0000:0000:0000:0000:0000
292will be used.
293The default prefixlen is 64.
294However, it is assumed to be 0 if
295.Cm default
296is specified for
297.Ar destination .
298Note that the qualifier works only for
299.Dv AF_INET6
300address family.
301.Pp
302Routes have associated flags which influence operation of the protocols
303when sending to destinations matched by the routes.
304These flags may be set (or sometimes cleared)
305by indicating the following corresponding modifiers:
306.Bd -literal
307-xresolve  RTF_XRESOLVE   - emit mesg on use (for external lookup)
308-iface    ~RTF_GATEWAY    - destination is directly reachable
309-static    RTF_STATIC     - manually added route
310-nostatic ~RTF_STATIC     - pretend route added by kernel or daemon
311-reject    RTF_REJECT     - emit an ICMP unreachable when matched
312-blackhole RTF_BLACKHOLE  - silently discard pkts (during updates)
313-proto1    RTF_PROTO1     - set protocol specific routing flag #1
314-proto2    RTF_PROTO2     - set protocol specific routing flag #2
315.Ed
316.Pp
317The optional modifiers
318.Fl rtt ,
319.Fl rttvar ,
320.Fl sendpipe ,
321.Fl recvpipe ,
322.Fl mtu ,
323.Fl hopcount ,
324.Fl expire ,
325and
326.Fl ssthresh
327provide initial values to quantities maintained in the routing entry
328by transport level protocols, such as TCP or TP4.
329These may be individually locked by preceding each such modifier to
330be locked by
331the
332.Fl lock
333meta-modifier, or one can
334specify that all ensuing metrics may be locked by the
335.Fl lockrest
336meta-modifier.
337.Pp
338Note that
339.Fl expire
340accepts expiration time of the route as the number of seconds since the
341Epoch
342.Pq see Xr time 3 .
343When the first character of the number is
344.Dq +
345or
346.Dq - ,
347it is interpreted as a value relative to the current time.
348.Pp
349The optional modifier
350.Fl fib Ar number
351specifies that the command will be applied to a non-default FIB.
352The
353.Ar number
354must be smaller than the
355.Va net.fibs
356.Xr sysctl 8
357MIB.
358When this modifier is not specified,
359or a negative number is specified,
360the default FIB shown in the
361.Va net.my_fibnum
362.Xr sysctl 8
363MIB will be used.
364.Pp
365The
366.Ar number
367allows multiple FIBs by a comma-separeted list and/or range
368specification.
369The
370.Qq Fl fib Li 2,4,6
371means the FIB number 2, 4, and 6.
372The
373.Qq Fl fib Li 1,3-5,6
374means the 1, 3, 4, 5, and 6.
375.Pp
376In a
377.Cm change
378or
379.Cm add
380command where the destination and gateway are not sufficient to specify
381the route (as in the ISO case where several interfaces may have the
382same address), the
383.Fl ifp
384or
385.Fl ifa
386modifiers may be used to determine the interface or interface address.
387.Pp
388All symbolic names specified for a
389.Ar destination
390or
391.Ar gateway
392are looked up first as a host name using
393.Xr gethostbyname 3 .
394If this lookup fails,
395.Xr getnetbyname 3
396is then used to interpret the name as that of a network.
397.Pp
398The
399.Nm
400utility uses a routing socket and the new message types
401.Dv RTM_ADD , RTM_DELETE , RTM_GET ,
402and
403.Dv RTM_CHANGE .
404As such, only the super-user may modify
405the routing tables.
406.Pp
407.Fx provides support for scalable multipath routing.
408It is activated by default, but can be turned off by setting the
409.Va net.route.multipath
410.Xr sysctl 8
411MIB to 0.
412.Pp
413There are multiple route lookup algorithms available.
414They can be configured by setting
415.Va net.route.algo.inet.algo
416for IPv4 and
417.Va net.route.algo.inet6.algo
418for IPv6
419.Xr sysctl 8
420MIBs.
421.Pp
422A list of available algorithms can be obtained by accessing the
423following
424.Xr sysctl 8
425MIBs
426.Va net.route.algo.inet.algo_list
427for IPv4 and
428.Va net.route.algo.inet6.algo_list
429for IPv6.
430.Pp
431The following algorithms are available:
432.Bl -tag -width radix_lockless
433.It radix
434Base system radix backend.
435.It bsearch
436Lockless binary search in a special IP array, tailored for a small FIB
437with <16 routes.
438This algorithm is only available for IPv4.
439.It radix_lockless
440Lockless immutable radix, re-created on every rtable change,
441tailored for a small FIB with <1000 routes.
442.It dpdk_lpm
443DPDK DIR24-8-based lookups, lockless datastructure, optimized
444for large FIBs.
445DIR24-8 relies on a large flat lookup table (64 MB with IPv4) which is
446directly indexed by the more significant portion of the lookup key.
447In order to use the dpdk_lpm algorithm one or both of the
448following kernel modules must be loaded via
449.Xr loader.conf 5 :
450.Bl -tag -width dpdk_lpm6.ko -compact
451.It dpdk_lpm4.ko
452DPDK implementation for IPv4.
453.It dpdk_lpm6.ko
454DPDK implementation for IPv6.
455.El
456.It dxr
457IPv4 only, lockless, compressed lookup structure
458(below 2.5 Bytes per IPv4 prefix for large BGP FIBs)
459which easily fits into modern CPU cache hierarchies,
460lookup throughput scales linearly with CPU cores.
461Loadable as a kernel module at runtime or via
462.Xr loader.conf 5 :
463.Bl -tag -width fib_dxr.ko -compact
464.It fib_dxr.ko
465.El
466.El
467.Pp
468The algorithms are selected automatically based on the size of the routing
469table of the system.
470They can be changed, but not every algorithm performs best for every
471FIB size.
472.Sh EXIT STATUS
473.Ex -std
474.Sh EXAMPLES
475Add a default route to the network routing table.
476This will send all packets for destinations not available in the routing table
477to the default gateway at 192.168.1.1:
478.Pp
479.Dl route add -net 0.0.0.0/0 192.168.1.1
480.Pp
481A shorter version of adding a default route can also be written as:
482.Pp
483.Dl route add default 192.168.1.1
484.Pp
485Add a static route to the 172.16.10.0/24 network via the 172.16.1.1 gateway:
486.Pp
487.Dl route add -net 172.16.10.0/24 172.16.1.1
488.Pp
489Change the gateway of an already established static route in the routing table:
490.Pp
491.Dl route change -net 172.16.10.0/24 172.16.1.2
492.Pp
493Display the route for a destination network:
494.Pp
495.Dl route show 172.16.10.0
496.Pp
497Delete a static route from the routing table:
498.Pp
499.Dl route delete -net 172.16.10.0/24 172.16.1.2
500.Pp
501Remove all routes from the routing table:
502.Pp
503.Dl route flush
504.Pp
505The routing table can be listed with
506.Xr netstat 1 .
507.Sh DIAGNOSTICS
508.Bl -diag
509.It "add [host \&| network ] %s: gateway %s flags %x"
510The specified route is being added to the tables.
511The
512values printed are from the routing table entry supplied
513in the
514.Xr ioctl 2
515call.
516If the gateway address used was not the primary address of the gateway
517(the first one returned by
518.Xr gethostbyname 3 ) ,
519the gateway address is printed numerically as well as symbolically.
520.It "delete [ host \&| network ] %s: gateway %s flags %x"
521As above, but when deleting an entry.
522.It "%s %s done"
523When the
524.Cm flush
525command is specified, each routing table entry deleted
526is indicated with a message of this form.
527.It "Network is unreachable"
528An attempt to add a route failed because the gateway listed was not
529on a directly-connected network.
530The next-hop gateway must be given.
531.It "not in table"
532A delete operation was attempted for an entry which
533was not present in the tables.
534.It "routing table overflow"
535An add operation was attempted, but the system was
536low on resources and was unable to allocate memory
537to create the new entry.
538.It "gateway uses the same route"
539A
540.Cm change
541operation resulted in a route whose gateway uses the
542same route as the one being changed.
543The next-hop gateway should be reachable through a different route.
544.El
545.Sh SEE ALSO
546.Xr netstat 1 ,
547.Xr netintro 4 ,
548.Xr route 4 ,
549.Xr loader.conf 5 ,
550.Xr arp 8 ,
551.Xr routed 8
552.Sh HISTORY
553The
554.Nm
555utility appeared in
556.Bx 4.2 .
557.Sh BUGS
558The first paragraph may have slightly exaggerated
559.Xr routed 8 Ns 's
560abilities.
561.Pp
562Currently, routes with the
563.Dv RTF_BLACKHOLE
564flag set need to have the gateway set to an instance of the
565.Xr lo 4
566driver, using the
567.Fl iface
568option, for the flag to have any effect; unless IP fast forwarding
569is enabled, in which case the meaning of the flag will always
570be honored.
571