1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
|
.\" $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: August 2 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.
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl d
Run in debug-only mode, i.e. don't actually modify the routing table.
.It 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.
.It Fl q
Suppress all output.
.It 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 .
.It Fl t
Write routing messages to a fake device
.Pa ( /dev/null )
instead of a real routing socket to test route manipulation.
.It Fl v
Print additional details.
.El
.Pp
The commands are as follows:
.Pp
.Bl -tag -width "XXXX" -compact
.It Xo
.Nm route
.Op Fl dnqtv
.Op Fl T Ar rtable
.Tg
.Cm add
.Op Ar modifier
.Ar destination
.Ar gateway
.Xc
.It 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.
.Pp
A number of modifiers can be used with
.Cm add
and
.Cm change ,
and as documented with the other commands:
.Pp
.Bl -tag -width Ds -compact
.It Ar flags
Various flags can be set on routes
(viewable using
.Cm show ) :
.Pp
.Bl -tag -width -blackhole -compact
.It Fl blackhole
silently discard packets
.It Fl cloning
generates a new route on use
.It Fl iface
destination is directly reachable
.It Fl llinfo
validly translates address to link address
.It Fl mpath
multiple gateways for a destination exist
.It Fl nostatic
pretend route added by kernel or daemon
.It Fl proto1
sets protocol specific routing flag #1
.It Fl proto2
sets protocol specific routing flag #2
.It Fl reject
emits an ICMP unreachable when matched
.It Fl static
manually added route (default)
.El
.Pp
The
.Fl blackhole
and
.Fl reject
flags require a
.Ar gateway
to the loopback interface,
either 127.0.0.1 or ::1.
.Pp
.It Oo Fl lock | Fl lockrest Oc Fl expire Ar n
.It 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.
.Pp
.It Fl host | net
Interpret
.Ar destination
as a host or network, respectively.
.Pp
.It Fl ifa Ar address
.It 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
.Pq Fl ifa
or name
.Pq Fl ifp .
.Pp
.It Fl label Ar label
Associate the route with a
.Ar label .
Route labels can be used to attach arbitrary information to a route.
.Pp
.It 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.
.Pp
.It 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.
.Pp
.It Fl netmask Ar mask
.It 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.
.Pp
.It 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
.Pp
.It 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.
.Pp
.It 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.
.Pp
.It 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.
.Pp
.It Xo
.Bk -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.
.Pp
.It 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.
.Pp
.It Xo
.Ic 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.
.Pp
.It 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.
.Pp
If
.Fl gateway
is specified, only routes whose gateway are in the
same address family as the destination are shown.
.Pp
If
.Fl label
is specified, only routes with the specified label are shown.
.Pp
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.
.Pp
Within the output of
.Cm show ,
the "Flags" column indicates what flags are set on the route.
The mapping between letters and flags is:
.Bl -column "1" "RTF_BLACKHOLE" "Protocol specific routing flag #1."
.It Dv 1 Ta Dv RTF_PROTO1 Ta "Protocol specific routing flag #1."
.It Dv 2 Ta Dv RTF_PROTO2 Ta "Protocol specific routing flag #2."
.It Dv 3 Ta Dv RTF_PROTO3 Ta "Protocol specific routing flag #3."
.It Dv B Ta Dv RTF_BLACKHOLE Ta "Just discard packets."
.It Dv b Ta Dv RTF_BROADCAST Ta "Correspond to a local broadcast address."
.It Dv C Ta Dv RTF_CLONING Ta "Generate new routes on use."
.It Dv c Ta Dv RTF_CLONED Ta "Cloned routes (generated from RTF_CLONING)."
.It Dv D Ta Dv RTF_DYNAMIC Ta "Created dynamically (by redirect)."
.It Dv G Ta Dv RTF_GATEWAY Ta "Dest requires forwarding by intermediary."
.It Dv H Ta Dv RTF_HOST Ta "Host entry (net otherwise)."
.It Dv h Ta Dv RTF_CACHED Ta "Referenced by gateway route."
.It Dv L Ta Dv RTF_LLINFO Ta "Valid protocol to link address translation."
.It Dv l Ta Dv RTF_LOCAL Ta "Correspond to a local address."
.It Dv M Ta Dv RTF_MODIFIED Ta "Modified dynamically (by redirect)."
.It Dv m Ta Dv RTF_MULTICAST Ta "Correspond to a multicast address."
.It Dv n Ta Dv RTF_CONNECTED Ta "Interface route."
.It Dv P Ta Dv RTF_MPATH Ta "Multipath route."
.It Dv R Ta Dv RTF_REJECT Ta "Host or net unreachable."
.It Dv S Ta Dv RTF_STATIC Ta "Manually added."
.It Dv T Ta Dv RTF_MPLS Ta "MPLS route."
.It Dv U Ta Dv RTF_UP Ta "Route usable."
.El
.Pp
.It Xo
.Ic 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:
.Pp
.Bl -tag -width "-inet6XXX" -offset indent -compact
.It Fl inet
IPv4 addresses;
see
.Xr ip 4
.It Fl inet6
IPv6 addresses;
see
.Xr ip6 4
.It Fl link
hardware (link-level) addresses
.It Fl mpls
MPLS addresses
.It Fl sa
actual
.Vt sockaddr
data, in hexadecimal format
.El
.Pp
.Ar destination
is assumed to be a route to a network
if any of the following apply:
.Pp
.Bl -bullet -compact
.It
the
.Fl net
modifier is used
.It
it is the word "default", equivalent to 0/0 or ::/0
.It
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
.It
it specifies the network portion either with
.Fl netmask
or
.Fl prefixlen
.El
.Pp
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.
.Pp
All symbolic names specified for a
.Ar destination
or
.Ar gateway
are looked up using
.Xr gethostbyname 3 .
.Sh FILES
.Bl -tag -width "/etc/mygate" -compact
.It Pa /etc/hosts
host and network name database
.It 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.
.Pp
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:
.Bl -tag -width Ds
.It 1
An invalid command line option was passed to
.Nm
or setting the routing table failed.
.It 126
.Ar command
was found but could not be invoked.
.It 127
.Ar command
could not be found.
.El
.Sh EXAMPLES
Show the current IPv4 routing tables,
without attempting to print hostnames symbolically:
.Pp
.Dl $ route -n show -inet
.Pp
Add a static
.Xr inet 4
route to the 192.168.5.0/24 network via the 192.168.0.1 gateway:
.Pp
.Dl # route add -inet 192.168.5.0/24 192.168.0.1
.Pp
Amend the
.Xr inet 4
route to the 192.168.5.0/24 network to use the 192.168.0.2 gateway:
.Pp
.Dl # route change -inet 192.168.5.0/24 192.168.0.2
.Pp
Delete the
.Xr inet 4
route to the 192.168.5.0/24 network:
.Pp
.Dl # route delete -inet 192.168.5.0/24
.Pp
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:
.Pp
.Dl # route add -inet6 2001:db8:efef::1 -cloning -link -iface vio0
.Dl # route add -inet6 default 2001:db8:efef::1
.Sh DIAGNOSTICS
.Bl -diag
.It "%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.
.It "%s %s done"
When the
.Cm flush
command is specified, each routing table entry deleted
is indicated with a message of this form.
.It "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.
.It "not in table"
A
.Cm delete
operation was attempted for an entry which
wasn't present in the tables.
.It "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
.Bx 4.2 .
IPv6 support was added by WIDE/KAME project.
.Pp
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
.Pa sys/net/rtsock.c
for details.
|