1.\" $NetBSD: route.8,v 1.41 2010/05/12 17:56:13 christos 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 August 6, 2006 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 osi , 152.Fl xns , 153.Fl atalk , 154.Fl inet , 155or 156.Fl inet6 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 osi , 233.Fl atalk , 234and 235.Fl link 236specify that all subsequent addresses are in the 237.Tn XNS , 238.Tn OSI , 239or 240.Tn AppleTalk 241address families, 242or are specified as link-level addresses, 243and the names must be numeric specifications rather than 244symbolic names. 245.Pp 246The optional 247.Fl netmask 248qualifier is intended 249to achieve the effect of an 250.Tn OSI 251.Tn ESIS 252redirect with the netmask option, 253or to manually add subnet routes with 254netmasks different from that of the implied network interface 255(as would otherwise be communicated using the OSPF or ISIS routing protocols). 256One specifies an additional ensuing address parameter 257(to be interpreted as a network mask). 258The implicit network mask generated in the 259.Dv AF_INET 260case 261can be overridden by making sure this option follows the destination parameter. 262.Fl prefixlen 263is also available for similar purpose, in IPv4 and IPv6 case. 264.Pp 265Routes have associated flags which influence operation of the protocols 266when sending to destinations matched by the routes. 267These flags may be set (or sometimes cleared) 268by indicating the following corresponding modifiers: 269.Bd -literal 270-cloning RTF_CLONING - generates a new route on use 271-nocloning ~RTF_CLONING - stop generating new routes on use 272-cloned RTF_CLONED - cloned route generated by RTF_CLONING 273-nocloned ~RTF_CLONED - prevent removal with RTF_CLONING parent 274-xresolve RTF_XRESOLVE - emit mesg on use (for external lookup) 275-iface ~RTF_GATEWAY - destination is directly reachable 276-static RTF_STATIC - manually added route 277-nostatic ~RTF_STATIC - pretend route added by kernel or daemon 278-reject RTF_REJECT - emit an ICMP unreachable when matched 279-noreject ~RTF_REJECT - clear reject flag 280-blackhole RTF_BLACKHOLE - silently discard pkts (during updates) 281-noblackhole ~RTF_BLACKHOLE - clear blackhole flag 282-proto1 RTF_PROTO1 - set protocol specific routing flag #1 283-proto2 RTF_PROTO2 - set protocol specific routing flag #2 284-llinfo RTF_LLINFO - validly translates proto addr to link addr 285.Ed 286.Pp 287The optional modifiers 288.Fl rtt , 289.Fl rttvar , 290.Fl sendpipe , 291.Fl recvpipe , 292.Fl mtu , 293.Fl hopcount , 294.Fl expire , 295and 296.Fl ssthresh 297provide initial values to quantities maintained in the routing entry 298by transport level protocols, such as TCP or TP4. 299These may be individually locked by preceding each such modifier to 300be locked by 301the 302.Fl lock 303meta-modifier, or one can 304specify that all ensuing metrics may be locked by the 305.Fl lockrest 306meta-modifier. 307.Pp 308In a 309.Cm change 310or 311.Cm add 312command where the destination and gateway are not sufficient to specify 313the route (as in the 314.Tn ISO 315case where several interfaces may have the 316same address), the 317.Fl ifp 318or 319.Fl ifa 320modifiers may be used to determine the interface or interface address. 321.Pp 322All symbolic names specified for a 323.Ar destination 324or 325.Ar gateway 326are looked up first as a host name using 327.Xr gethostbyname 3 . 328If this lookup fails, 329.Xr getnetbyname 3 330is then used to interpret the name as that of a network. 331.Pp 332.Nm 333uses a routing socket and the new message types 334.Dv RTM_ADD , 335.Dv RTM_DELETE , 336.Dv RTM_GET , 337and 338.Dv RTM_CHANGE . 339As such, only the super-user may modify 340the routing tables. 341.Sh EXIT STATUS 342The 343.Nm 344utility exits 0 on success, and \*[Gt]0 if an error occurs. 345This includes the use of the 346.Cm get 347command to look up a route that is incomplete. 348.Sh EXAMPLES 349This sets the default route to 192.168.0.1: 350.Dl route add default 192.168.0.1 351This shows all routes, without DNS resolution (this is useful if the 352DNS is not available): 353.Dl route -n show 354To install a static route through 10.200.0.1 to reach the network 355192.168.1.0/28, use this: 356.Dl route add -net 192.168.1.0 -netmask 255.255.255.240 10.200.0.1 357.Sh DIAGNOSTICS 358.Bl -tag -width Ds 359.It Sy "add [host \&| network ] %s: gateway %s flags %x" 360The specified route is being added to the tables. 361The values printed are from the routing table entry supplied in the 362.Xr ioctl 2 363call. 364If the gateway address used was not the primary address of the gateway 365(the first one returned by 366.Xr gethostbyname 3 ) , 367the gateway address is printed numerically as well as symbolically. 368.It Sy "delete [ host \&| network ] %s: gateway %s flags %x" 369As above, but when deleting an entry. 370.It Sy "%s %s done" 371When the 372.Cm flush 373command is specified, each routing table entry deleted 374is indicated with a message of this form. 375.It Sy "Network is unreachable" 376An attempt to add a route failed because the gateway listed was not 377on a directly-connected network. 378The next-hop gateway must be given. 379.It Sy "not in table" 380A delete operation was attempted for an entry which 381wasn't present in the tables. 382.It Sy "routing table overflow" 383An add operation was attempted, but the system was 384low on resources and was unable to allocate memory 385to create the new entry. 386.It Sy "Permission denied" 387The attempted operation is privileged. 388Only root may modify the routing tables. 389These privileges are enforced by the kernel. 390.El 391.Sh SEE ALSO 392.Xr esis 4 , 393.Xr netintro 4 , 394.Xr route 4 , 395.Xr routed 8 , 396.Xr sysctl 8 397.\" .Xr XNSrouted 8 398.Sh HISTORY 399The 400.Nm 401command appeared in 402.Bx 4.2 . 403IPv6 support was added by WIDE/KAME project. 404.Sh BUGS 405The first paragraph may have slightly exaggerated 406.Xr routed 8 Ns 's 407abilities. 408.Pp 409Some uses of the 410.Fl ifa 411or 412.Fl ifp 413modifiers with the add command will incorrectly fail with a 414.Dq Network is unreachable 415message if there is no default route. 416See case 417.Dv RTM_ADD 418in 419.Pa sys/net/rtsock.c:route_output 420for details. 421