xref: /netbsd-src/sbin/route/route.8 (revision 62f324d0121177eaf2e0384f92fd9ca2a751c795)
1.\"	$NetBSD: route.8,v 1.47 2013/03/01 18:25:17 joerg Exp $
2.\"
3.\" Copyright (c) 1983, 1991, 1993
4.\"	The Regents of the University of California.  All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\" 3. Neither the name of the University nor the names of its contributors
15.\"    may be used to endorse or promote products derived from this software
16.\"    without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\"     @(#)route.8	8.4 (Berkeley) 6/1/94
31.\"
32.Dd February 5, 2013
33.Dt ROUTE 8
34.Os
35.Sh NAME
36.Nm route
37.Nd manually manipulate the routing tables
38.Sh SYNOPSIS
39.Nm
40.Op Fl fnqSsv
41.Ar command
42.Oo
43.Op Ar modifiers
44.Ar args
45.Oc
46.Sh DESCRIPTION
47.Nm
48is a utility used to manually manipulate the network
49routing tables.
50Except for setting up the default route, it is normally not needed,
51as a system routing table management daemon such as
52.Xr routed 8 ,
53should tend to this task.
54.Pp
55.Nm
56can be used to modify nearly any aspect of the routing policy,
57except packet forwarding, which can be manipulated through the
58.Xr sysctl 8
59command.
60.Pp
61The
62.Nm
63utility supports a limited number of general options,
64but a rich command language, enabling the user to specify
65any arbitrary request that could be delivered via the
66programmatic interface discussed in
67.Xr route 4 .
68.Pp
69.Bl -tag -width Ds
70.It Fl f
71Remove all routes (as per
72.Cm flush ) .
73If used in conjunction with the
74.Cm add ,
75.Cm change ,
76.Cm delete
77or
78.Cm get
79commands,
80.Nm
81removes the routes before performing the command.
82.It Fl n
83Bypasses attempts to print host and network names symbolically
84when reporting actions.
85(The process of translating between symbolic
86names and numerical equivalents can be quite time consuming, and
87may require correct operation of the network; thus it may be expedient
88to forgo this, especially when attempting to repair networking operations).
89.It Fl q
90Suppress all output from commands that manipulate the routing table.
91.It Fl S
92Print a space when a flag is missing so that flags are vertically aligned
93instead of printing the flags that are set as a contiguous string.
94.It Fl s
95(short) Suppresses all output from a
96.Cm get
97command except for the actual gateway that will be used.
98How the gateway is printed depends on the type of route being looked up.
99.It Fl v
100(verbose) Print additional details.
101.El
102.Pp
103The
104.Nm
105utility provides several commands:
106.Pp
107.Bl -tag -width Fl -compact
108.It Cm add
109Add a route.
110.It Cm flush
111Remove all routes.
112.It Cm flushall
113Remove all routes including the default gateway.
114.It Cm delete
115Delete a specific route.
116.It Cm change
117Change aspects of a route (such as its gateway).
118.It Cm get
119Lookup and display the route for a destination.
120.It Cm show
121Print out the route table similar to "netstat \-r" (see
122.Xr netstat 1 ) .
123.It Cm monitor
124Continuously report any changes to the routing information base,
125routing lookup misses, or suspected network partitionings.
126.El
127.Pp
128The monitor command has the syntax
129.Pp
130.Bd -filled -offset indent -compact
131.Nm
132.Op Fl n
133.Cm monitor
134.Ed
135.Pp
136The flush command has the syntax
137.Pp
138.Bd -filled -offset indent -compact
139.Nm
140.Op Fl n
141.Cm flush
142.Op Ar family
143.Ed
144.Pp
145If the
146.Cm flush
147command is specified,
148.Nm
149will ``flush'' the routing tables of all gateway entries.
150When the address family is specified by any of the
151.Fl xns ,
152.Fl atalk ,
153.Fl inet ,
154.Fl inet6 ,
155or
156.Fl mpls
157modifiers, only routes having destinations with addresses in the
158delineated family will be manipulated.
159.Pp
160The other commands have the following syntax:
161.Pp
162.Bd -filled -offset indent -compact
163.Nm
164.Op Fl n
165.Ar command
166.Op Fl net No \&| Fl host
167.Ar destination gateway
168.Ed
169.Pp
170where
171.Ar destination
172is the destination host or network, and
173.Ar gateway
174is the next-hop intermediary via which packets should be routed.
175Routes to a particular host may be distinguished from those to
176a network by interpreting the Internet address specified as the
177.Ar destination
178argument.
179The optional modifiers
180.Fl net
181and
182.Fl host
183force the destination to be interpreted as a network or a host, respectively.
184Otherwise, if the
185.Ar destination
186has a ``local address part'' of
187.Dv INADDR_ANY ,
188or if the
189.Ar destination
190is the symbolic name of a network, then the route is
191assumed to be to a network; otherwise, it is presumed to be a
192route to a host.
193Optionally, the
194.Ar destination
195can also be specified in the
196.Ar net Ns / Ns Ar bits
197format.
198.Pp
199For example,
200.Li 128.32
201is interpreted as
202.Fl host Li 128.0.0.32 ;
203.Li 128.32.130
204is interpreted as
205.Fl host Li 128.32.0.130 ;
206.Fl net Li 128.32
207is interpreted as
208.Li 128.32.0.0 ;
209and
210.Fl net Li 128.32.130
211is interpreted as
212.Li 128.32.130.0 .
213.Pp
214The keyword
215.Cm default
216can be used as the
217.Ar destination
218to set up a default route to a smart
219.Ar gateway .
220If no other routes match, this default route will be used as a last resort.
221.Pp
222If the destination is directly reachable
223via an interface requiring
224no intermediary system to act as a gateway, the
225.Fl interface
226modifier should be specified;
227the gateway given is the address of this host on the common network,
228indicating the interface to be used for transmission.
229.Pp
230The optional modifiers
231.Fl xns ,
232.Fl atalk ,
233and
234.Fl link
235specify that all subsequent addresses are in the
236.Tn XNS ,
237or
238.Tn AppleTalk
239address families,
240or are specified as link-level addresses in the form described in
241.Xr link_addr 3 ,
242and the names must be numeric specifications rather than
243symbolic names.
244.Pp
245The optional modifiers
246.Fl mpls
247and
248.Fl tag
249specify that all subsequent addresses are in the
250.Tn MPLS
251address family.
252See
253.Xr mpls 4
254for examples about setting routes involving MPLS.
255.Pp
256The optional
257.Fl netmask
258qualifier is intended
259to achieve the effect of an
260.Tn ESIS
261redirect with the netmask option,
262or to manually add subnet routes with
263netmasks different from that of the implied network interface
264(as would otherwise be communicated using the OSPF or ISIS routing protocols).
265One specifies an additional ensuing address parameter
266(to be interpreted as a network mask).
267The implicit network mask generated in the
268.Dv AF_INET
269case
270can be overridden by making sure this option follows the destination parameter.
271.Fl prefixlen
272is also available for similar purpose, in IPv4 and IPv6 case.
273.Pp
274Routes have associated flags which influence operation of the protocols
275when sending to destinations matched by the routes.
276These flags may be set (or sometimes cleared)
277by indicating the following corresponding modifiers:
278.Bd -literal
279-cloning      RTF_CLONING    - generates a new route on use
280-nocloning   ~RTF_CLONING    - stop generating new routes on use
281-cloned       RTF_CLONED     - cloned route generated by RTF_CLONING
282-nocloned    ~RTF_CLONED     - prevent removal with RTF_CLONING parent
283-xresolve     RTF_XRESOLVE   - emit mesg on use (for external lookup)
284-iface       ~RTF_GATEWAY    - destination is directly reachable
285-static       RTF_STATIC     - manually added route
286-nostatic    ~RTF_STATIC     - pretend route added by kernel or daemon
287-reject       RTF_REJECT     - emit an ICMP unreachable when matched
288-noreject    ~RTF_REJECT     - clear reject flag
289-blackhole    RTF_BLACKHOLE  - silently discard pkts (during updates)
290-noblackhole ~RTF_BLACKHOLE  - clear blackhole flag
291-proto1       RTF_PROTO1     - set protocol specific routing flag #1
292-proto2       RTF_PROTO2     - set protocol specific routing flag #2
293-llinfo       RTF_LLINFO     - validly translates proto addr to link addr
294-proxy        RTF_ANNOUNCE   - make entry a link level proxy
295.Ed
296.Pp
297The optional modifiers
298.Fl rtt ,
299.Fl rttvar ,
300.Fl sendpipe ,
301.Fl recvpipe ,
302.Fl mtu ,
303.Fl hopcount ,
304.Fl expire ,
305and
306.Fl ssthresh
307provide initial values to quantities maintained in the routing entry
308by transport level protocols, such as TCP or TP4.
309These may be individually locked by preceding each such modifier to
310be locked by
311the
312.Fl lock
313meta-modifier, or one can
314specify that all ensuing metrics may be locked by the
315.Fl lockrest
316meta-modifier.
317.Pp
318In a
319.Cm change
320or
321.Cm add
322command where the destination and gateway are not sufficient to specify
323the route the
324.Fl ifp
325or
326.Fl ifa
327modifiers may be used to determine the interface or interface address.
328.Pp
329All symbolic names specified for a
330.Ar destination
331or
332.Ar gateway
333are looked up first as a host name using
334.Xr gethostbyname 3 .
335If this lookup fails,
336.Xr getnetbyname 3
337is then used to interpret the name as that of a network.
338.Pp
339.Nm
340uses a routing socket and the new message types
341.Dv RTM_ADD ,
342.Dv RTM_DELETE ,
343.Dv RTM_GET ,
344and
345.Dv RTM_CHANGE .
346As such, only the super-user may modify
347the routing tables.
348.Sh EXIT STATUS
349The
350.Nm
351utility exits 0 on success, and \*[Gt]0 if an error occurs.
352This includes the use of the
353.Cm get
354command to look up a route that is incomplete.
355.Sh EXAMPLES
356This sets the default route to 192.168.0.1:
357.Dl route add default 192.168.0.1
358This shows all routes, without DNS resolution (this is useful if the
359DNS is not available):
360.Dl route -n show
361To install a static route through 10.200.0.1 to reach the network
362192.168.1.0/28, use this:
363.Dl route add -net 192.168.1.0 -netmask 255.255.255.240 10.200.0.1
364.Sh DIAGNOSTICS
365.Bl -tag -width Ds
366.It Sy "add [host \&| network ] %s: gateway %s flags %x"
367The specified route is being added to the tables.
368The values printed are from the routing table entry supplied in the
369.Xr ioctl 2
370call.
371If the gateway address used was not the primary address of the gateway
372(the first one returned by
373.Xr gethostbyname 3 ) ,
374the gateway address is printed numerically as well as symbolically.
375.It Sy "delete [ host \&| network ] %s: gateway %s flags %x"
376As above, but when deleting an entry.
377.It Sy "%s %s done"
378When the
379.Cm flush
380command is specified, each routing table entry deleted
381is indicated with a message of this form.
382.It Sy "Network is unreachable"
383An attempt to add a route failed because the gateway listed was not
384on a directly-connected network.
385The next-hop gateway must be given.
386.It Sy "not in table"
387A delete operation was attempted for an entry which
388wasn't present in the tables.
389.It Sy "routing table overflow"
390An add operation was attempted, but the system was
391low on resources and was unable to allocate memory
392to create the new entry.
393.It Sy "Permission denied"
394The attempted operation is privileged.
395Only root may modify the routing tables.
396These privileges are enforced by the kernel.
397.El
398.Sh SEE ALSO
399.Xr esis 4 ,
400.Xr mpls 4 ,
401.Xr netintro 4 ,
402.Xr route 4 ,
403.Xr routed 8 ,
404.Xr sysctl 8
405.\" .Xr XNSrouted 8
406.Sh HISTORY
407The
408.Nm
409command appeared in
410.Bx 4.2 .
411IPv6 support was added by WIDE/KAME project.
412.Sh BUGS
413The first paragraph may have slightly exaggerated
414.Xr routed 8 Ns 's
415abilities.
416.Pp
417Some uses of the
418.Fl ifa
419or
420.Fl ifp
421modifiers with the add command will incorrectly fail with a
422.Dq Network is unreachable
423message if there is no default route.
424See case
425.Dv RTM_ADD
426in
427.Pa sys/net/rtsock.c:route_output
428for details.
429