xref: /freebsd/sbin/route/route.8 (revision 2a664c03e55254b0f3b32dcdfc78179c0a57a8d2)
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.\" 4. 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.\" $FreeBSD$
30.\"
31.Dd March 24, 2012
32.Dt ROUTE 8
33.Os
34.Sh NAME
35.Nm route
36.Nd manually manipulate the routing tables
37.Sh SYNOPSIS
38.Nm
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 d
66Run in debug-only mode, i.e., do not actually modify the routing table.
67.It Fl n
68Bypass attempts to print host and network names symbolically
69when reporting actions.
70(The process of translating between symbolic
71names and numerical equivalents can be quite time consuming, and
72may require correct operation of the network; thus it may be expedient
73to forget this, especially when attempting to repair networking operations).
74.It Fl t
75Run in test-only mode.
76.Pa /dev/null
77is used instead of a socket.
78.It Fl v
79(verbose) Print additional details.
80.It Fl q
81Suppress all output from the
82.Cm add , change , delete ,
83and
84.Cm flush
85commands.
86.El
87.Pp
88The
89.Nm
90utility provides the following commands:
91.Pp
92.Bl -tag -width Fl -compact
93.It Cm add
94Add a route.
95.It Cm flush
96Remove all routes.
97.It Cm delete
98Delete a specific route.
99.It Cm del
100Another name for the
101.Cm delete
102command.
103.It Cm change
104Change aspects of a route (such as its gateway).
105.It Cm get
106Lookup and display the route for a destination.
107.It Cm monitor
108Continuously report any changes to the routing information base,
109routing lookup misses, or suspected network partitionings.
110.It Cm show
111Another name for the
112.Cm get
113command.
114.El
115.Pp
116The monitor command has the syntax:
117.Pp
118.Bd -ragged -offset indent -compact
119.Nm
120.Op Fl n
121.Cm monitor
122.Ed
123.Pp
124The flush command has the syntax:
125.Pp
126.Bd -ragged -offset indent -compact
127.Nm
128.Op Fl n
129.Cm flush
130.Op Ar family
131.Ed
132.Pp
133If the
134.Cm flush
135command is specified,
136.Nm
137will ``flush'' the routing tables of all gateway entries.
138When the address family may is specified by any of the
139.Fl osi ,
140.Fl xns ,
141.Fl atalk ,
142.Fl inet6 ,
143or
144.Fl inet
145modifiers, only routes having destinations with addresses in the
146delineated family will be deleted.
147.Pp
148The other commands have the following syntax:
149.Pp
150.Bd -ragged -offset indent -compact
151.Nm
152.Op Fl n
153.Ar command
154.Op Fl net No \&| Fl host
155.Ar destination gateway
156.Op Ar netmask
157.Ed
158.Pp
159where
160.Ar destination
161is the destination host or network,
162.Ar gateway
163is the next-hop intermediary via which packets should be routed.
164Routes to a particular host may be distinguished from those to
165a network by interpreting the Internet address specified as the
166.Ar destination
167argument.
168The optional modifiers
169.Fl net
170and
171.Fl host
172force the destination to be interpreted as a network or a host, respectively.
173Otherwise, if the
174.Ar destination
175has a
176.Dq local address part
177of
178INADDR_ANY
179.Pq Li 0.0.0.0 ,
180or if the
181.Ar destination
182is the symbolic name of a network, then the route is
183assumed to be to a network; otherwise, it is presumed to be a
184route to a host.
185Optionally, the
186.Ar destination
187could also be specified in the
188.Ar net Ns / Ns Ar bits
189format.
190.Pp
191For example,
192.Li 128.32
193is interpreted as
194.Fl host Li 128.0.0.32 ;
195.Li 128.32.130
196is interpreted as
197.Fl host Li 128.32.0.130 ;
198.Fl net Li 128.32
199is interpreted as
200.Li 128.32.0.0;
201.Fl net Li 128.32.130
202is interpreted as
203.Li 128.32.130.0;
204and
205.Li 192.168.64/20
206is interpreted as
207.Fl net Li 192.168.64 Fl netmask Li 255.255.240.0 .
208.Pp
209A
210.Ar destination
211of
212.Ar default
213is a synonym for
214.Fl net Li 0.0.0.0 ,
215which is the default route.
216.Pp
217If the destination is directly reachable
218via an interface requiring
219no intermediary system to act as a gateway, the
220.Fl interface
221modifier should be specified;
222the gateway given is the address of this host on the common network,
223indicating the interface to be used for transmission.
224Alternately, if the interface is point to point the name of the interface
225itself may be given, in which case the route remains valid even
226if the local or remote addresses change.
227.Pp
228The optional modifiers
229.Fl xns ,
230.Fl osi ,
231.Fl atalk ,
232and
233.Fl link
234specify that all subsequent addresses are in the
235.Tn XNS ,
236.Tn OSI ,
237or
238.Tn AppleTalk
239address families,
240or are specified as link-level addresses,
241and the names must be numeric specifications rather than
242symbolic names.
243.Pp
244The optional
245.Fl netmask
246modifier is intended
247to achieve the effect of an
248.Tn OSI
249.Tn ESIS
250redirect with the netmask option,
251or to manually add subnet routes with
252netmasks different from that of the implied network interface
253(as would otherwise be communicated using the OSPF or ISIS routing protocols).
254One specifies an additional ensuing address parameter
255(to be interpreted as a network mask).
256The implicit network mask generated in the AF_INET case
257can be overridden by making sure this option follows the destination parameter.
258.Pp
259For
260.Dv AF_INET6 ,
261the
262.Fl prefixlen
263qualifier
264is available instead of the
265.Fl mask
266qualifier because non-continuous masks are not allowed in IPv6.
267For example,
268.Fl prefixlen Li 32
269specifies network mask of
270.Li ffff:ffff:0000:0000:0000:0000:0000:0000
271to be used.
272The default value of prefixlen is 64 to get along with
273the aggregatable address.
274But 0 is assumed if
275.Cm default
276is specified.
277Note that the qualifier works only for
278.Dv AF_INET6
279address family.
280.Pp
281Routes have associated flags which influence operation of the protocols
282when sending to destinations matched by the routes.
283These flags may be set (or sometimes cleared)
284by indicating the following corresponding modifiers:
285.Bd -literal
286-xresolve  RTF_XRESOLVE   - emit mesg on use (for external lookup)
287-iface    ~RTF_GATEWAY    - destination is directly reachable
288-static    RTF_STATIC     - manually added route
289-nostatic ~RTF_STATIC     - pretend route added by kernel or daemon
290-reject    RTF_REJECT     - emit an ICMP unreachable when matched
291-blackhole RTF_BLACKHOLE  - silently discard pkts (during updates)
292-proto1    RTF_PROTO1     - set protocol specific routing flag #1
293-proto2    RTF_PROTO2     - set protocol specific routing flag #2
294.Ed
295.Pp
296The optional modifiers
297.Fl rtt ,
298.Fl rttvar ,
299.Fl sendpipe ,
300.Fl recvpipe ,
301.Fl mtu ,
302.Fl hopcount ,
303.Fl expire ,
304and
305.Fl ssthresh
306provide initial values to quantities maintained in the routing entry
307by transport level protocols, such as TCP or TP4.
308These may be individually locked by preceding each such modifier to
309be locked by
310the
311.Fl lock
312meta-modifier, or one can
313specify that all ensuing metrics may be locked by the
314.Fl lockrest
315meta-modifier.
316.Pp
317In a
318.Cm change
319or
320.Cm add
321command where the destination and gateway are not sufficient to specify
322the route (as in the
323.Tn ISO
324case where several interfaces may have the
325same address), the
326.Fl ifp
327or
328.Fl ifa
329modifiers may be used to determine the interface or interface address.
330.Pp
331All symbolic names specified for a
332.Ar destination
333or
334.Ar gateway
335are looked up first as a host name using
336.Xr gethostbyname 3 .
337If this lookup fails,
338.Xr getnetbyname 3
339is then used to interpret the name as that of a network.
340.Pp
341The
342.Nm
343utility uses a routing socket and the new message types
344.Dv RTM_ADD , RTM_DELETE , RTM_GET ,
345and
346.Dv RTM_CHANGE .
347As such, only the super-user may modify
348the routing tables.
349.Sh EXIT STATUS
350.Ex -std
351.Sh EXAMPLES
352Add a default route to the network routing table.
353This will send all packets for destinations not available in the routing table
354to the default gateway at 192.168.1.1:
355.Pp
356.Dl route add -net 0.0.0.0/0 192.168.1.1
357.Pp
358A shorter version of adding a default route can also be written as:
359.Pp
360.Dl route add default 192.168.1.1
361.Pp
362Add a static route to the 172.16.10.0/24 network via the 172.16.1.1 gateway:
363.Pp
364.Dl route add -net 172.16.10.0/24 172.16.1.1
365.Pp
366Change the gateway of an already established static route in the routing table:
367.Pp
368.Dl route change -net 172.16.10.0/24 172.16.1.2
369.Pp
370Display the route for a destination network:
371.Pp
372.Dl route show 172.16.10.0
373.Pp
374Delete a static route from the routing table:
375.Pp
376.Dl route delete -net 172.16.10.0/24 172.16.1.2
377.Pp
378Remove all routes from the routing table:
379.Pp
380.Dl route flush
381.Sh DIAGNOSTICS
382.Bl -diag
383.It "add [host \&| network ] %s: gateway %s flags %x"
384The specified route is being added to the tables.
385The
386values printed are from the routing table entry supplied
387in the
388.Xr ioctl 2
389call.
390If the gateway address used was not the primary address of the gateway
391(the first one returned by
392.Xr gethostbyname 3 ) ,
393the gateway address is printed numerically as well as symbolically.
394.It "delete [ host \&| network ] %s: gateway %s flags %x"
395As above, but when deleting an entry.
396.It "%s %s done"
397When the
398.Cm flush
399command is specified, each routing table entry deleted
400is indicated with a message of this form.
401.It "Network is unreachable"
402An attempt to add a route failed because the gateway listed was not
403on a directly-connected network.
404The next-hop gateway must be given.
405.It "not in table"
406A delete operation was attempted for an entry which
407was not present in the tables.
408.It "routing table overflow"
409An add operation was attempted, but the system was
410low on resources and was unable to allocate memory
411to create the new entry.
412.It "gateway uses the same route"
413A
414.Cm change
415operation resulted in a route whose gateway uses the
416same route as the one being changed.
417The next-hop gateway should be reachable through a different route.
418.El
419.Sh SEE ALSO
420.\".Xr esis 4 ,
421.Xr netintro 4 ,
422.Xr route 4 ,
423.Xr arp 8 ,
424.Xr IPXrouted 8 ,
425.Xr routed 8
426.\".Xr XNSrouted 8
427.Sh HISTORY
428The
429.Nm
430utility appeared in
431.Bx 4.2 .
432.Sh BUGS
433The first paragraph may have slightly exaggerated
434.Xr routed 8 Ns 's
435abilities.
436.Pp
437Currently, routes with the
438.Dv RTF_BLACKHOLE
439flag set need to have the gateway set to an instance of the
440.Xr lo 4
441driver, using the
442.Fl iface
443option, for the flag to have any effect; unless IP fast forwarding
444is enabled, in which case the meaning of the flag will always
445be honored.
446