1IP-ROUTE(8)                          Linux                         IP-ROUTE(8)
2
3
4

NAME

6       ip-route - routing table management
7

SYNOPSIS

9       ip [ ip-OPTIONS ] route  { COMMAND | help }
10
11
12       ip route { show | flush } SELECTOR
13
14       ip route save SELECTOR
15
16       ip route restore
17
18       ip route get ADDRESS [ from ADDRESS iif STRING  ] [ oif STRING ] [ tos
19               TOS ] [ vrf NAME ]
20
21       ip route { add | del | change | append | replace } ROUTE
22
23       SELECTOR := [ root PREFIX ] [ match PREFIX ] [ exact PREFIX ] [ table
24               TABLE_ID ] [ vrf NAME ] [ proto RTPROTO ] [ type TYPE ] [ scope
25               SCOPE ]
26
27       ROUTE := NODE_SPEC [ INFO_SPEC ]
28
29       NODE_SPEC := [ TYPE ] PREFIX [ tos TOS ] [ table TABLE_ID ] [ proto
30               RTPROTO ] [ scope SCOPE ] [ metric METRIC ]
31
32       INFO_SPEC := NH OPTIONS FLAGS [ nexthop NH ] ...
33
34       NH := [ encap ENCAP ] [ via [ FAMILY ] ADDRESS ] [ dev STRING ] [
35               weight NUMBER ] NHFLAGS
36
37       FAMILY := [ inet | inet6 | ipx | dnet | mpls | bridge | link ]
38
39       OPTIONS := FLAGS [ mtu NUMBER ] [ advmss NUMBER ] [ as [ to ] ADDRESS ]
40               rtt TIME ] [ rttvar TIME ] [ reordering NUMBER ] [ window NUM‐
41               BER ] [ cwnd NUMBER ] [ ssthresh REALM ] [ realms REALM ] [
42               rto_min TIME ] [ initcwnd NUMBER ] [ initrwnd NUMBER ] [ fea‐
43               tures FEATURES ] [ quickack BOOL ] [ congctl NAME ] [ pref PREF
44               ] [ expires TIME ]
45
46       TYPE := [ unicast | local | broadcast | multicast | throw | unreachable
47               | prohibit | blackhole | nat ]
48
49       TABLE_ID := [ local| main | default | all | NUMBER ]
50
51       SCOPE := [ host | link | global | NUMBER ]
52
53       NHFLAGS := [ onlink | pervasive ]
54
55       RTPROTO := [ kernel | boot | static | NUMBER ]
56
57       FEATURES := [ ecn | ]
58
59       PREF := [ low | medium | high ]
60
61       ENCAP := [ MPLS | IP| BPF ]
62
63       ENCAP_MPLS := mpls [ LABEL ]
64
65       ENCAP_IP := ip id TUNNEL_ID dst REMOTE_IP [ tos TOS ] [ ttl TTL ]
66
67
68       ENCAP_BPF := bpf [ in PROG ] [ out PROG ] [ xmit PROG ] [ headroom SIZE
69               ]
70
71

DESCRIPTION

73       ip route is used to manipulate entries in the kernel routing tables.
74
75       Route types:
76
77               unicast - the route entry describes real paths to the destina‐
78               tions covered by the route prefix.
79
80
81               unreachable - these destinations are unreachable. Packets are
82               discarded and the ICMP message host unreachable is generated.
83               The local senders get an EHOSTUNREACH error.
84
85
86               blackhole - these destinations are unreachable. Packets are
87               discarded silently.  The local senders get an EINVAL error.
88
89
90               prohibit - these destinations are unreachable. Packets are dis‐
91               carded and the ICMP message communication administratively pro‐
92               hibited is generated. The local senders get an EACCES error.
93
94
95               local - the destinations are assigned to this host. The packets
96               are looped back and delivered locally.
97
98
99               broadcast - the destinations are broadcast addresses. The pack‐
100               ets are sent as link broadcasts.
101
102
103               throw - a special control route used together with policy
104               rules. If such a route is selected, lookup in this table is
105               terminated pretending that no route was found. Without policy
106               routing it is equivalent to the absence of the route in the
107               routing table. The packets are dropped and the ICMP message net
108               unreachable is generated. The local senders get an ENETUNREACH
109               error.
110
111
112               nat - a special NAT route. Destinations covered by the prefix
113               are considered to be dummy (or external) addresses which
114               require translation to real (or internal) ones before forward‐
115               ing. The addresses to translate to are selected with the
116               attribute via.  Warning: Route NAT is no longer supported in
117               Linux 2.6.
118
119
120               anycast - not implemented the destinations are anycast
121               addresses assigned to this host. They are mainly equivalent to
122               local with one difference: such addresses are invalid when used
123               as the source address of any packet.
124
125
126               multicast - a special type used for multicast routing. It is
127               not present in normal routing tables.
128
129
130       Route tables: Linux-2.x can pack routes into several routing tables
131       identified by a number in the range from 1 to 2^31 or by name from the
132       file /etc/iproute2/rt_tables By default all normal routes are inserted
133       into the main table (ID 254) and the kernel only uses this table when
134       calculating routes.  Values (0, 253, 254, and 255) are reserved for
135       built-in use.
136
137
138       Actually, one other table always exists, which is invisible but even
139       more important. It is the local table (ID 255). This table consists of
140       routes for local and broadcast addresses. The kernel maintains this ta‐
141       ble automatically and the administrator usually need not modify it or
142       even look at it.
143
144       The multiple routing tables enter the game when policy routing is used.
145
146
147       ip route add
148              add new route
149
150       ip route change
151              change route
152
153       ip route replace
154              change or add new one
155
156              to TYPE PREFIX (default)
157                     the destination prefix of the route. If TYPE is omitted,
158                     ip assumes type unicast.  Other values of TYPE are listed
159                     above.  PREFIX is an IP or IPv6 address optionally fol‐
160                     lowed by a slash and the prefix length. If the length of
161                     the prefix is missing, ip assumes a full-length host
162                     route. There is also a special PREFIX default - which is
163                     equivalent to IP 0/0 or to IPv6 ::/0.
164
165
166              tos TOS
167
168              dsfield TOS
169                     the Type Of Service (TOS) key. This key has no associated
170                     mask and the longest match is understood as: First, com‐
171                     pare the TOS of the route and of the packet. If they are
172                     not equal, then the packet may still match a route with a
173                     zero TOS.  TOS is either an 8 bit hexadecimal number or
174                     an identifier from /etc/iproute2/rt_dsfield.
175
176
177              metric NUMBER
178
179              preference NUMBER
180                     the preference value of the route.  NUMBER is an arbi‐
181                     trary 32bit number.
182
183
184              table TABLEID
185                     the table to add this route to.  TABLEID may be a number
186                     or a string from the file /etc/iproute2/rt_tables.  If
187                     this parameter is omitted, ip assumes the main table,
188                     with the exception of local, broadcast and nat routes,
189                     which are put into the local table by default.
190
191
192              vrf NAME
193                     the vrf name to add this route to. Implicitly means the
194                     table associated with the VRF.
195
196
197              dev NAME
198                     the output device name.
199
200
201              via [ FAMILY ] ADDRESS
202                     the address of the nexthop router, in the address family
203                     FAMILY.  Actually, the sense of this field depends on the
204                     route type.  For normal unicast routes it is either the
205                     true next hop router or, if it is a direct route
206                     installed in BSD compatibility mode, it can be a local
207                     address of the interface. For NAT routes it is the first
208                     address of the block of translated IP destinations.
209
210
211              src ADDRESS
212                     the source address to prefer when sending to the destina‐
213                     tions covered by the route prefix.
214
215
216              realm REALMID
217                     the realm to which this route is assigned.  REALMID may
218                     be a number or a string from the file
219                     /etc/iproute2/rt_realms.
220
221
222              mtu MTU
223
224              mtu lock MTU
225                     the MTU along the path to the destination. If the modi‐
226                     fier lock is not used, the MTU may be updated by the ker‐
227                     nel due to Path MTU Discovery. If the modifier lock is
228                     used, no path MTU discovery will be tried, all packets
229                     will be sent without the DF bit in IPv4 case or frag‐
230                     mented to MTU for IPv6.
231
232
233              window NUMBER
234                     the maximal window for TCP to advertise to these destina‐
235                     tions, measured in bytes. It limits maximal data bursts
236                     that our TCP peers are allowed to send to us.
237
238
239              rtt TIME
240                     the initial RTT ('Round Trip Time') estimate. If no suf‐
241                     fix is specified the units are raw values passed directly
242                     to the routing code to maintain compatibility with previ‐
243                     ous releases.  Otherwise if a suffix of s, sec or secs is
244                     used to specify seconds and ms, msec or msecs to specify
245                     milliseconds.
246
247
248
249              rttvar TIME (2.3.15+ only)
250                     the initial RTT variance estimate. Values are specified
251                     as with rtt above.
252
253
254              rto_min TIME (2.6.23+ only)
255                     the minimum TCP Retransmission TimeOut to use when commu‐
256                     nicating with this destination. Values are specified as
257                     with rtt above.
258
259
260              ssthresh NUMBER (2.3.15+ only)
261                     an estimate for the initial slow start threshold.
262
263
264              cwnd NUMBER (2.3.15+ only)
265                     the clamp for congestion window. It is ignored if the
266                     lock flag is not used.
267
268
269              initcwnd NUMBER (2.5.70+ only)
270                     the initial congestion window size for connections to
271                     this destination.  Actual window size is this value mul‐
272                     tiplied by the MSS (``Maximal Segment Size'') for same
273                     connection. The default is zero, meaning to use the val‐
274                     ues specified in RFC2414.
275
276
277              initrwnd NUMBER (2.6.33+ only)
278                     the initial receive window size for connections to this
279                     destination.  Actual window size is this value multiplied
280                     by the MSS of the connection.  The default value is zero,
281                     meaning to use Slow Start value.
282
283
284              features FEATURES (3.18+only)
285                     Enable or disable per-route features. Only available fea‐
286                     ture at this time is ecn to enable explicit congestion
287                     notification when initiating connections to the given
288                     destination network.  When responding to a connection
289                     request from the given network, ecn will also be used
290                     even if the net.ipv4.tcp_ecn sysctl is set to 0.
291
292
293              quickack BOOL (3.11+ only)
294                     Enable or disable quick ack for connections to this des‐
295                     tination.
296
297
298              congctl NAME (3.20+ only)
299
300              congctl lock NAME (3.20+ only)
301                     Sets a specific TCP congestion control algorithm only for
302                     a given destination.  If not specified, Linux keeps the
303                     current global default TCP congestion control algorithm,
304                     or the one set from the application. If the modifier lock
305                     is not used, an application may nevertheless overwrite
306                     the suggested congestion control algorithm for that des‐
307                     tination. If the modifier lock is used, then an applica‐
308                     tion is not allowed to overwrite the specified congestion
309                     control algorithm for that destination, thus it will be
310                     enforced/guaranteed to use the proposed algorithm.
311
312
313              advmss NUMBER (2.3.15+ only)
314                     the MSS ('Maximal Segment Size') to advertise to these
315                     destinations when establishing TCP connections. If it is
316                     not given, Linux uses a default value calculated from the
317                     first hop device MTU.  (If the path to these destination
318                     is asymmetric, this guess may be wrong.)
319
320
321              reordering NUMBER (2.3.15+ only)
322                     Maximal reordering on the path to this destination.  If
323                     it is not given, Linux uses the value selected with
324                     sysctl variable net/ipv4/tcp_reordering.
325
326
327              nexthop NEXTHOP
328                     the nexthop of a multipath route.  NEXTHOP is a complex
329                     value with its own syntax similar to the top level argu‐
330                     ment lists:
331
332                             via [ FAMILY ] ADDRESS - is the nexthop router.
333
334
335                             dev NAME - is the output device.
336
337
338                             weight NUMBER - is a weight for this element of a
339                             multipath route reflecting its relative bandwidth
340                             or quality.
341
342                     The internal buffer used in iproute2 limits the maximum
343                     number of nexthops that may be specified in one go. If
344                     only ADDRESS is given, the current buffer size allows for
345                     144 IPv6 nexthops and 253 IPv4 ones. For IPv4, this
346                     effectively limits the number of nexthops possible per
347                     route. With IPv6, further nexthops may be appended to the
348                     same route via ip route append command.
349
350
351              scope SCOPE_VAL
352                     the scope of the destinations covered by the route pre‐
353                     fix.  SCOPE_VAL may be a number or a string from the file
354                     /etc/iproute2/rt_scopes.  If this parameter is omitted,
355                     ip assumes scope global for all gatewayed unicast routes,
356                     scope link for direct unicast and broadcast routes and
357                     scope host for local routes.
358
359
360              protocol RTPROTO
361                     the routing protocol identifier of this route.  RTPROTO
362                     may be a number or a string from the file
363                     /etc/iproute2/rt_protos.  If the routing protocol ID is
364                     not given, ip assumes protocol boot (i.e. it assumes the
365                     route was added by someone who doesn't understand what
366                     they are doing). Several protocol values have a fixed
367                     interpretation.  Namely:
368
369                             redirect - the route was installed due to an ICMP
370                             redirect.
371
372
373                             kernel - the route was installed by the kernel
374                             during autoconfiguration.
375
376
377                             boot - the route was installed during the bootup
378                             sequence.  If a routing daemon starts, it will
379                             purge all of them.
380
381
382                             static - the route was installed by the adminis‐
383                             trator to override dynamic routing. Routing dae‐
384                             mon will respect them and, probably, even adver‐
385                             tise them to its peers.
386
387
388                             ra - the route was installed by Router Discovery
389                             protocol.
390
391
392                     The rest of the values are not reserved and the adminis‐
393                     trator is free to assign (or not to assign) protocol
394                     tags.
395
396
397              onlink pretend that the nexthop is directly attached to this
398                     link, even if it does not match any interface prefix.
399
400
401              pref PREF
402                     the IPv6 route preference.  PREF is a string specifying
403                     the route preference as defined in RFC4191 for Router
404                     Discovery messages. Namely:
405
406                             low - the route has a lowest priority
407
408
409                             medium - the route has a default priority
410
411
412                             high - the route has a highest priority
413
414
415
416              encap ENCAPTYPE ENCAPHDR
417                     attach tunnel encapsulation attributes to this route.
418
419                     ENCAPTYPE is a string specifying the supported encapsula‐
420                     tion type. Namely:
421
422                             mpls - encapsulation type MPLS
423
424                             ip - IP encapsulation (Geneve, GRE, VXLAN, ...)
425
426                             bpf - Execution of BPF program
427
428
429                     ENCAPHDR is a set of encapsulation attributes specific to
430                     the ENCAPTYPE.
431
432                             mpls
433                               MPLSLABEL - mpls label stack with labels sepa‐
434                               rated by /
435
436
437                             ip
438                               id TUNNEL_ID dst REMOTE_IP [ tos TOS ] [ ttl
439                               TTL ]
440
441
442                             bpf
443                               in PROG - BPF program to execute for incoming
444                               packets
445
446
447                               out PROG - BPF program to execute for outgoing
448                               packets
449
450
451                               xmit PROG - BPF program to execute for trans‐
452                               mitted packets
453
454
455                               headroom SIZE - Size of header BPF program will
456                               attach (xmit)
457
458
459
460
461              expires TIME (4.4+ only)
462                     the route will be deleted after the expires time.  Only
463                     support IPv6 at present.
464
465
466       ip route delete
467              delete route
468              ip route del has the same arguments as ip route add, but their
469              semantics are a bit different.
470
471              Key values (to, tos, preference and table) select the route to
472              delete. If optional attributes are present, ip verifies that
473              they coincide with the attributes of the route to delete.  If no
474              route with the given key and attributes was found, ip route del
475              fails.
476
477
478       ip route show
479              list routes
480              the command displays the contents of the routing tables or the
481              route(s) selected by some criteria.
482
483
484              to SELECTOR (default)
485                     only select routes from the given range of destinations.
486                     SELECTOR consists of an optional modifier (root, match or
487                     exact) and a prefix.  root PREFIX selects routes with
488                     prefixes not shorter than PREFIX.  F.e.  root 0/0 selects
489                     the entire routing table.  match PREFIX selects routes
490                     with prefixes not longer than PREFIX.  F.e.  match
491                     10.0/16 selects 10.0/16, 10/8 and 0/0, but it does not
492                     select 10.1/16 and 10.0.0/24.  And exact PREFIX (or just
493                     PREFIX) selects routes with this exact prefix. If neither
494                     of these options are present, ip assumes root 0/0 i.e. it
495                     lists the entire table.
496
497
498              tos TOS
499
500              dsfield TOS
501                     only select routes with the given TOS.
502
503
504              table TABLEID
505                     show the routes from this table(s). The default setting
506                     is to show table main.  TABLEID may either be the ID of a
507                     real table or one of the special values:
508
509                             all - list all of the tables.
510
511                             cache - dump the routing cache.
512
513
514              vrf NAME
515                     show the routes for the table associated with the vrf
516                     name
517
518
519              cloned
520
521              cached list cloned routes i.e. routes which were dynamically
522                     forked from other routes because some route attribute
523                     (f.e. MTU) was updated.  Actually, it is equivalent to
524                     table cache.
525
526
527              from SELECTOR
528                     the same syntax as for to, but it binds the source
529                     address range rather than destinations.  Note that the
530                     from option only works with cloned routes.
531
532
533              protocol RTPROTO
534                     only list routes of this protocol.
535
536
537              scope SCOPE_VAL
538                     only list routes with this scope.
539
540
541              type TYPE
542                     only list routes of this type.
543
544
545              dev NAME
546                     only list routes going via this device.
547
548
549              via [ FAMILY ] PREFIX
550                     only list routes going via the nexthop routers selected
551                     by PREFIX.
552
553
554              src PREFIX
555                     only list routes with preferred source addresses selected
556                     by PREFIX.
557
558
559              realm REALMID
560
561              realms FROMREALM/TOREALM
562                     only list routes with these realms.
563
564
565       ip route flush
566              flush routing tables
567              this command flushes routes selected by some criteria.
568
569
570              The arguments have the same syntax and semantics as the argu‐
571              ments of ip route show, but routing tables are not listed but
572              purged. The only difference is the default action: show dumps
573              all the IP main routing table but flush prints the helper page.
574
575
576              With the -statistics option, the command becomes verbose. It
577              prints out the number of deleted routes and the number of rounds
578              made to flush the routing table. If the option is given twice,
579              ip route flush also dumps all the deleted routes in the format
580              described in the previous subsection.
581
582
583       ip route get
584              get a single route
585              this command gets a single route to a destination and prints its
586              contents exactly as the kernel sees it.
587
588
589              to ADDRESS (default)
590                     the destination address.
591
592
593              from ADDRESS
594                     the source address.
595
596
597              tos TOS
598
599              dsfield TOS
600                     the Type Of Service.
601
602
603              iif NAME
604                     the device from which this packet is expected to arrive.
605
606
607              oif NAME
608                     force the output device on which this packet will be
609                     routed.
610
611
612              vrf NAME
613                     force the vrf device on which this packet will be routed.
614
615
616              connected
617                     if no source address (option from) was given, relookup
618                     the route with the source set to the preferred address
619                     received from the first lookup.  If policy routing is
620                     used, it may be a different route.
621
622
623              Note that this operation is not equivalent to ip route show.
624              show shows existing routes.  get resolves them and creates new
625              clones if necessary. Essentially, get is equivalent to sending a
626              packet along this path.  If the iif argument is not given, the
627              kernel creates a route to output packets towards the requested
628              destination.  This is equivalent to pinging the destination with
629              a subsequent ip route ls cache, however, no packets are actually
630              sent. With the iif argument, the kernel pretends that a packet
631              arrived from this interface and searches for a path to forward
632              the packet.
633
634
635       ip route save
636              save routing table information to stdout
637              This command behaves like ip route show except that the output
638              is raw data suitable for passing to ip route restore.
639
640
641       ip route restore
642              restore routing table information from stdin
643              This command expects to read a data stream as returned from ip
644              route save.  It will attempt to restore the routing table infor‐
645              mation exactly as it was at the time of the save, so any trans‐
646              lation of information in the stream (such as device indexes)
647              must be done first. Any existing routes are left unchanged. Any
648              routes specified in the data stream that already exist in the
649              table will be ignored.
650
651

NOTES

653       Starting with Linux kernel version 3.6, there is no routing cache for
654       IPv4 anymore. Hence ip route show cached will never print any entries
655       on systems with this or newer kernel versions.
656
657

EXAMPLES

659       ip ro
660           Show all route entries in the kernel.
661
662       ip route add default via 192.168.1.1 dev eth0
663           Adds a default route (for all addresses) via the local gateway
664           192.168.1.1 that can be reached on device eth0.
665
666       ip route add 10.1.1.0/30 encap mpls 200/300 via 10.1.1.1 dev eth0
667           Adds an ipv4 route with mpls encapsulation attributes attached to
668           it.
669

SEE ALSO

671       ip(8)
672
673

AUTHOR

675       Original Manpage by Michail Litvak <mci@owl.openwall.com>
676
677
678
679iproute2                          13 Dec 2012                      IP-ROUTE(8)
Impressum