IP-ROUTE(8)

โœจ IP-ROUTE(8) โ€” routing table management โœจ

okay bestie, gather round, because ip-route is THE main character of your Linux networking journey and i need you to understand her ๐Ÿ’… (this is from the ip-route manual page, section 8, Linux, iykyk)


๐Ÿฆ‹ SYNOPSIS ๐Ÿฆ‹

so here's the vibe, the full spellbook, no skips:

ip [ ip-OPTIONS ] route  { COMMAND | help }

ip route { show | flush } SELECTOR

ip route save SELECTOR

ip route restore

ip route get ROUTE_GET_FLAGS [ to ] ADDRESS [ from ADDRESS iif STRING  ]
        [ oif STRING ] [ mark MARK ] [ tos TOS ] [ vrf NAME ] [ uid
        NUMBER ] [ ipproto PROTOCOL ] [ sport NUMBER ] [ dport NUMBER ]
        [ as ADDRESS ] [ flowlabel FLOWLABEL ]

ip route { add | del | change | append | replace } ROUTE

SELECTOR := [ root PREFIX ] [ match PREFIX ] [ exact PREFIX ] [ table
        TABLE_ID ] [ vrf NAME ] [ proto RTPROTO ] [ type TYPE ] [ scope
        SCOPE ]

ROUTE := NODE_SPEC [ INFO_SPEC ]

NODE_SPEC := [ TYPE ] PREFIX [ tos TOS ] [ table TABLE_ID ] [ proto
        RTPROTO ] [ scope SCOPE ] [ metric METRIC ] [ ttl-propagate {
        enabled | disabled } ]

INFO_SPEC := { NH | nhid ID } OPTIONS FLAGS [ nexthop NH ] ...

NH := [ encap ENCAP ] [ via [ FAMILY ] ADDRESS ] [ dev STRING ] [ weight
        NUMBER ] NHFLAGS

FAMILY := [ inet | inet6 | mpls | bridge | link ]

OPTIONS := FLAGS [ mtu NUMBER ] [ advmss NUMBER ] [ as [ to ] ADDRESS ]
        rtt TIME ] [ rttvar TIME ] [ reordering NUMBER ] [ window NUMBER
        ] [ cwnd NUMBER ] [ ssthresh NUMBER ] [ realms REALM ] [ rto_min
        TIME ] [ initcwnd NUMBER ] [ initrwnd NUMBER ] [ features
        FEATURES ] [ quickack BOOL ] [ congctl NAME ] [ pref PREF ] [
        expires TIME ] [ fastopen_no_cookie BOOL ]

TYPE := [ unicast | local | broadcast | multicast | throw | unreachable
        | prohibit | blackhole | nat ]

TABLE_ID := [ local| main | default | all | NUMBER ]

SCOPE := [ host | link | global | NUMBER ]

NHFLAGS := [ onlink | pervasive ]

RTPROTO := [ kernel | boot | static | NUMBER ]

FEATURES := [ ecn | tcp_usec_ts ]

PREF := [ low | medium | high ]

ENCAP := [ ENCAP_MPLS | ENCAP_IP | ENCAP_BPF | ENCAP_SEG6 |
        ENCAP_SEG6LOCAL | ENCAP_IOAM6 ]

ENCAP_MPLS := mpls [ LABEL ] [ ttl TTL ]

ENCAP_IP := ip id TUNNEL_ID dst REMOTE_IP [ src SRC ] [ tos TOS ] [ ttl
        TTL ] [ key ] [ csum ] [ seq ] [ GENEVE_OPTS | VXLAN_OPTS |
        ERSPAN_OPTS ]

ENCAP_BPF := bpf [ in PROG ] [ out PROG ] [ xmit PROG ] [ headroom SIZE
        ]

ENCAP_SEG6 := seg6 mode [ encap | encap.red | inline | l2encap |
        l2encap.red ] [ tunsrc ADDRESS ] segs SEGMENTS [ hmac KEYID ] [
        lookup TABLEID ]

ENCAP_SEG6LOCAL := seg6local action SEG6_ACTION [ SEG6_ACTION_PARAM ] [
        count ]

ENCAP_IOAM6 := ioam6 [ freq K/N ] mode [ inline | encap | auto ] [
        tunsrc ADDRESS ] [ tundst ADDRESS ] trace prealloc type
        IOAM6_TRACE_TYPE ns IOAM6_NAMESPACE size IOAM6_TRACE_SIZE

ROUTE_GET_FLAGS := ROUTE_GET_FLAG [ ROUTE_GET_FLAGS ]

ROUTE_GET_FLAG := [ connected | fibmatch | notify ]

like. it's a lot. but we're gonna get through it together, one flag at a time ๐Ÿซถ


๐ŸŒธ DESCRIPTION ๐ŸŒธ

so ip route is literally the tool you use to mess with entries in the kernel routing tables. that's the whole assignment. routing table management, periodt ๐Ÿ‘‘

the route types (vibe check on each one) ๐ŸŽ€

  • unicast โ€” ok so this is the normal one. the route entry describes the real paths to the destinations covered by the route prefix. actual routes. the standard. nothing weird.
  • unreachable โ€” these destinations are unreachable, full stop. packets get discarded, and the kernel generates the ICMP message host unreachable. local senders get an EHOSTUNREACH error back. brutal but informative ๐Ÿ’€
  • blackhole โ€” also unreachable, but make it โœจsilentโœจ. packets are discarded silently, no ICMP, nothing. local senders get an EINVAL error. it's giving ghosting fr fr.
  • prohibit โ€” unreachable and petty about it. packets get discarded and the kernel generates the ICMP message communication administratively prohibited. local senders get an EACCES error.
  • local โ€” the destinations are assigned to this host. packets are looped back and delivered locally. it's home ๐Ÿ’–
  • broadcast โ€” the destinations are broadcast addresses, and the packets get sent as link broadcasts. loud. proud. ๐Ÿ“ฃ
  • throw โ€” ooh this one's a special control route used together with policy rules. if such a route is selected, lookup in this table is terminated, pretending that no route was found. without policy routing it's basically equivalent to the route just not existing in the routing table. packets are dropped and the ICMP message net unreachable is generated. local senders get an ENETUNREACH error.
  • nat โ€” a special NAT route. destinations covered by the prefix are considered to be dummy (or external) addresses which require translation to real (or internal) ones before forwarding. the addresses to translate to are selected with the via attribute.
โš ๏ธ Warning: Route NAT is no longer supported in Linux 2.6. i'm just the messenger bestie ๐Ÿ˜ญ
  • anycast โ€” not implemented. the destinations are anycast addresses assigned to this host. they're mainly equivalent to local with one difference: such addresses are invalid when used as the source address of any packet. ๐Ÿ™ˆ
  • multicast โ€” a special type used for multicast routing. it is not present in normal routing tables.

route tables ๐Ÿ’œ

okay so Linux-2.x can pack routes into several routing tables, identified by either:

  • a number in the range from 1 to 2^32-1, or
  • a name from /usr/share/iproute2/rt_tables or /etc/iproute2/rt_tables (this one has precedence if it exists)

by default all normal routes are inserted into the main table (ID 254) and the kernel only uses this table when calculating routes. the values 0, 253, 254, and 255 are reserved for built-in use โ€” don't touch, they're spoken for ๐Ÿ’…

actually, there's one other table that always exists, and she's invisible but even MORE important: the local table (ID 255). this table consists of routes for local and broadcast addresses. the kernel maintains this table automatically and the administrator usually need not modify it or even look at it. so like, pretend you don't see her. she's fine. she's thriving.

the multiple routing tables enter the game when policy routing is used. that's the plot twist ๐ŸŽญ


๐Ÿ”ฅ the route commands ๐Ÿ”ฅ

ip route add

add new route. that's it. that's the tweet. โœจ

ip route change

change route. ๐Ÿ’ซ

ip route replace

change or add new one โ€” she does both, she's flexible, she contains multitudes ๐Ÿ‘‘


and now the actual route options, grab a snack because we're going in:

  • to TYPE PREFIX (default) โ€” the destination prefix of the route. if TYPE is omitted, ip assumes type unicast. other values of TYPE are listed above. PREFIX is an IP or IPv6 address optionally followed by a slash and the prefix length. if the length of the prefix is missing, ip assumes a full-length host route. there's also a special PREFIX of default โ€” which is equivalent to IP 0/0 or to IPv6 ::/0. ๐ŸŒˆ
  • tos TOS
  • dsfield TOS โ€” the Type Of Service (TOS) key. this key has no associated mask, and the longest match is understood like this: first, compare the TOS of the route and of the packet. if they are not equal, then the packet may still match a route with a zero TOS. TOS is either an 8 bit hexadecimal number or an identifier from /usr/share/iproute2/rt_dsfield or /etc/iproute2/rt_dsfield (has precedence if exists).
  • metric NUMBER
  • preference NUMBER โ€” the preference value of the route. NUMBER is an arbitrary 32bit number, where routes with lower values are preferred. lowkey competitive.
  • table TABLEID โ€” the table to add this route to. TABLEID may be a number or a string from /usr/share/iproute2/rt_tables or /etc/iproute2/rt_tables (has precedence if exists). if this parameter is omitted, ip assumes the main table, with the exception of local, broadcast and nat routes, which are put into the local table by default. ๐ŸŽ€
  • vrf NAME โ€” the vrf name to add this route to. implicitly means the table associated with the VRF.
  • dev NAME โ€” the output device name.
  • via [ FAMILY ] ADDRESS โ€” the address of the nexthop router, in the address family FAMILY. actually, the sense of this field depends on the route type. for normal unicast routes it is either the true next hop router or, if it is a direct route installed in BSD compatibility mode, it can be a local address of the interface. for NAT routes it is the first address of the block of translated IP destinations. she's versatile like that ๐Ÿ’…
  • src ADDRESS โ€” the source address to prefer when sending to the destinations covered by the route prefix.
  • realm REALMID โ€” the realm to which this route is assigned. REALMID may be a number or a string from /usr/share/iproute2/rt_realms or /etc/iproute2/rt_realms (has precedence if exists).
  • mtu MTU
  • mtu lock MTU โ€” the MTU along the path to the destination. if the modifier lock is not used, the MTU may be updated by the kernel due to Path MTU Discovery. if the modifier lock is used, no path MTU discovery will be tried, all packets will be sent without the DF bit in IPv4 case or fragmented to MTU for IPv6. no take-backs, the lock is serious ๐Ÿ”’
  • window NUMBER โ€” the maximal window for TCP to advertise to these destinations, measured in bytes. it limits maximal data bursts that our TCP peers are allowed to send to us.
  • rtt TIME โ€” the initial RTT ('Round Trip Time') estimate. if no suffix is specified the units are raw values passed directly to the routing code to maintain compatibility with previous releases. otherwise, if a suffix of s, sec or secs is used you're specifying seconds, and ms, msec or msecs means milliseconds.
  • rttvar TIME (Linux 2.3.15+ only) โ€” the initial RTT variance estimate. values are specified as with rtt above.
  • rto_min TIME (Linux 2.6.23+ only) โ€” the minimum TCP Retransmission TimeOut to use when communicating with this destination. values are specified as with rtt above.
  • ssthresh NUMBER (Linux 2.3.15+ only) โ€” an estimate for the initial slow start threshold.
  • cwnd NUMBER (Linux 2.3.15+ only) โ€” the clamp for congestion window. โš ๏ธ it is ignored if the lock flag is not used.
  • initcwnd NUMBER (Linux 2.5.70+ only) โ€” the initial congestion window size for connections to this destination. actual window size is this value multiplied by the MSS (Maximal Segment Size) for same connection. the default is zero, meaning to use the values specified in RFC2414. ๐Ÿ“š
  • initrwnd NUMBER (Linux 2.6.33+ only) โ€” the initial receive window size for connections headed to this destination. The actual window size you get is this value multiplied by the MSS of the connection ๐Ÿซถ. Default is 0, and 0 means "just use the Slow Start value, bestie."
  • features FEATURES โ€” turn per-route features on or off โœจ. The available features are ecn and tcp_usec_ts.
    • ecn (Linux 3.18+ only) โ€” enables explicit congestion notification when initiating connections to the given destination network ๐Ÿ”ฅ. And when responding to a connection request from that network, ecn gets used anyway โ€” even if the net.ipv4.tcp_ecn sysctl is set to 0. Yeah, it's like that.
    • tcp_usec_ts (Linux 6.7+ only) โ€” enables microsecond-resolution TCP timestamps for connections to/from the given destination network, instead of the default millisecond resolution โฑ๏ธ. Glow up for your timestamps.
  • quickack BOOL (Linux 3.11+ only) โ€” enable or disable quick ack for connections to this destination ๐Ÿ‘‘
  • fastopen_no_cookie BOOL (Linux 4.15+ only) โ€” enable TCP Fastopen without a cookie for connections to this destination ๐Ÿช๐Ÿšซ
  • congctl NAME (Linux 3.20+ only)
  • congctl lock NAME (Linux 3.20+ only) โ€” sets a specific TCP congestion control algorithm just for one destination, iykyk. Leave it out and Linux keeps whatever the current global default TCP congestion control algorithm is, or whatever the app set ๐ŸŒ€. If you don't use the lock modifier, an application can still overwrite the suggested congestion control algorithm for that destination โ€” lowkey rude but allowed ๐Ÿ™ˆ. If you do use the lock modifier, then an application is not allowed to overwrite the specified congestion control algorithm for that destination, so it will be enforced/guaranteed to use the proposed algorithm. Periodt ๐Ÿ’…
  • advmss NUMBER (Linux 2.3.15+ only) โ€” the MSS ('Maximal Segment Size') to advertise to these destinations when establishing TCP connections. If you don't give it, Linux uses a default value calculated from the first hop device MTU. (And if the path to these destinations is asymmetric, that guess may be wrong ๐Ÿ˜ญ โ€” sorry, it tried.)
  • reordering NUMBER (Linux 2.3.15+ only) โ€” maximal reordering on the path to this destination. If you don't give it, Linux uses the value selected with sysctl variable net/ipv4/tcp_reordering ๐ŸŽ€
  • nexthop NEXTHOP โ€” the nexthop of a multipath route ๐Ÿ›ฃ๏ธ. NEXTHOP is a complex value with its own syntax, similar to the top level argument lists:
    • via [ FAMILY ] ADDRESS โ€” is the nexthop router.
    • dev NAME โ€” is the output device.
    • weight NUMBER โ€” is a weight for this element of a multipath route, reflecting its relative bandwidth or quality.

Heads up bestie ๐Ÿซฃ: the internal buffer used in iproute2 limits the maximum number of nexthops you can specify in one go. If only ADDRESS is given, the current buffer size allows for 144 IPv6 nexthops and 253 IPv4 ones. For IPv4, this effectively limits the number of nexthops possible per route. With IPv6, further nexthops may be appended to the same route via the ip route append command ๐ŸŒˆ

  • scope SCOPE_VAL โ€” the scope of the destinations covered by the route prefix ๐Ÿงญ. SCOPE_VAL may be a number or a string from /usr/share/iproute2/rt_scopes or /etc/iproute2/rt_scopes (which has precedence if it exists). If you omit this parameter, ip assumes scope global for all gatewayed unicast routes, scope link for direct unicast and broadcast routes, and scope host for local routes. It just knows ๐Ÿ’…
  • protocol RTPROTO โ€” the routing protocol identifier of this route ๐Ÿ”–. RTPROTO may be a number or a string from /usr/share/iproute2/rt_protos or /etc/iproute2/rt_protos (has precedence if exists). If the routing protocol ID is not given, ip assumes protocol boot โ€” i.e. it assumes the route was added by someone who doesn't understand what they are doing ๐Ÿ’€ (not me calling anyone out butโ€ฆ exactly that). Several protocol values have a fixed interpretation, namely:
    • redirect โ€” the route was installed due to an ICMP redirect.
    • kernel โ€” the route was installed by the kernel during autoconfiguration.
    • boot โ€” the route was installed during the bootup sequence. If a routing daemon starts, it will purge all of them ๐Ÿงน.
    • static โ€” the route was installed by the administrator to override dynamic routing. Routing daemon will respect them and, probably, even advertise them to its peers ๐Ÿ‘‘.
    • ra โ€” the route was installed by Router Discovery protocol.

The rest of the values are not reserved, so the administrator is free to assign (or not to assign) protocol tags ๐ŸŒธ

  • onlink โ€” pretend that the nexthop is directly attached to this link, even if it does not match any interface prefix ๐Ÿ™ˆ
  • pref PREF โ€” the IPv6 route preference ๐Ÿฆ‹. PREF is a string specifying the route preference as defined in RFC4191 for Router Discovery messages. Namely:
    • low โ€” the route has a lowest priority
    • medium โ€” the route has a default priority
    • high โ€” the route has a highest priority
  • nhid ID โ€” use nexthop object with given id as nexthop specification ๐Ÿ”—
  • encap ENCAPTYPE ENCAPHDR โ€” attach tunnel encapsulation attributes to this route ๐Ÿ“ฆ

ENCAPTYPE is a string specifying the supported encapsulation type. Namely:

  • mpls โ€” encapsulation type MPLS
  • ip โ€” IP encapsulation (Geneve, GRE, VXLAN, ...)
  • bpf โ€” Execution of BPF program
  • seg6 โ€” encapsulation type IPv6 Segment Routing
  • seg6local โ€” local SRv6 segment processing
  • ioam6 โ€” encapsulation type IPv6 IOAM
  • xfrm โ€” encapsulation type XFRM

ENCAPHDR is a set of encapsulation attributes specific to the ENCAPTYPE โœจ

  • mpls
    • MPLSLABEL โ€” mpls label stack with labels separated by /
    • ttl TTL โ€” TTL to use for MPLS header or 0 to inherit from IP header
  • ip
    • id TUNNEL_ID โ€” Tunnel ID (for example VNI in VXLAN tunnel)
    • dst REMOTE_IP โ€” Outer header destination IP address (IPv4 or IPv6)
    • src SRC โ€” Outer header source IP address (IPv4 or IPv6)
    • tos TOS โ€” Outer header TOS
    • ttl TTL โ€” Outer header TTL
    • key โ€” Outer header flags with key in GRE tunnel
    • csum โ€” Outer header flags with csum in GRE tunnel
    • seq โ€” Outer header flags with seq in GRE tunnel
    • GENEVE_OPTS โ€” Specified in the form CLASS:TYPE:DATA, where CLASS is represented as a 16bit hexadecimal value, TYPE as an 8bit hexadecimal value and DATA as a variable length hexadecimal value. Additionally multiple options may be listed using a comma delimiter ๐ŸŒˆ
    • VXLAN_OPTS โ€” Specified in the form GBP, as a 32bit number. Multiple options is not supported ๐Ÿšซ
    • ERSPAN_OPTS โ€” Specified in the form VERSION:INDEX:DIR:HWID, where VERSION is represented as a 8bit number, INDEX as an 32bit number, DIR and HWID as a 8bit number. Multiple options is not supported. Note INDEX is used when VERSION is 1, and DIR and HWID are used when VERSION is 2.
  • bpf
    • in PROG โ€” BPF program to execute for incoming packets
    • out PROG โ€” BPF program to execute for outgoing packets
    • xmit PROG โ€” BPF program to execute for transmitted packets
    • headroom SIZE โ€” Size of header BPF program will attach (xmit)
  • seg6
    • mode inline โ€” Directly insert Segment Routing Header after IPv6 header
    • mode encap โ€” Encapsulate packet in an outer IPv6 header with SRH
    • mode encap.red โ€” Encapsulate packet in an outer IPv6 header with SRH applying the reduced segment list. When there is only one segment and the HMAC is not present, the SRH is omitted.
    • mode l2encap โ€” Encapsulate ingress L2 frame within an outer IPv6 header and SRH
    • mode l2encap.red โ€” Encapsulate ingress L2 frame within an outer IPv6 header and SRH applying the reduced segment list. When there is only one segment and the HMAC is not present, the SRH is omitted.
  • tunsrc ADDRESS โ€” the IPv6 address of the tunnel source (that's the outer header, bestie) ๐Ÿ’– and heads up: it is not used with inline mode. It's also fully optional โ€” if you don't hand it over, the tunnel source address gets picked based on the per-netns configuration (ip sr tunsrc set ADDRESS) or, if that isn't configured either, it just gets dynamically resolved. And if you do provide it? It takes priority over the per-netns configuration and the dynamic resolution. Main character energy ๐Ÿ’…
  • SEGMENTS โ€” a list of comma-separated IPv6 addresses โœจ
  • KEYID โ€” a numerical value, written in decimal representation. See ip-sr(8). ๐Ÿ“–
  • lookup TABLEID โ€” the table for the post-encap SID route lookup, like, the lookup for the route of the first SID. TABLEID is either a number or a string pulled from /usr/share/iproute2/rt_tables or /etc/iproute2/rt_tables (and that second one wins if it exists, no cap). Also, table id 0 is not a valid value ๐Ÿšซ. When you omit it, this lookup uses the current routing context, e.g. the tables selected according to the routing policy database.

๐ŸŒธ seg6local

SEG6_ACTION [ SEG6_ACTION_PARAM ] [ count ] โ€” this is the operation to perform on matching packets.

The optional count attribute is there to collect statistics on the processing of actions, and it's giving data ๐Ÿ“Š. Three counters are implemented: 1) packets correctly processed; 2) bytes correctly processed; 3) packets that cause a processing error (i.e., missing SID List, wrong SID List, etc). To retrieve the counters related to an action, use the -s flag in the show command. Periodt.

The following actions are currently supported (Linux 4.14+ only โ€” yeah, don't try this on your ancient kernel ๐Ÿ’€).

  • End [ flavors FLAVORS ] โ€” regular SRv6 processing, as an intermediate segment endpoint. This action only accepts packets with a non-zero Segments Left value. Every other matching packet gets dropped. ๐Ÿซฃ The presence of flavors can change the regular processing of an End behavior according to the user-provided Flavor operations and the information carried in the packet. See the Flavors parameters section.
  • End.X nh6 NEXTHOP [ flavors FLAVORS ] โ€” regular SRv6 processing as an intermediate segment endpoint, and additionally forward the processed packets to the given next-hop ๐Ÿฆ‹. This action only accepts packets with a non-zero Segments Left value. Other matching packets are dropped. The presence of flavors can change the regular processing of an End.X behavior according to the user-provided Flavor operations and the information carried in the packet. See the Flavors parameters section.
  • End.DX6 nh6 NEXTHOP โ€” decapsulate the inner IPv6 packet and forward it to the specified next-hop. If the argument is set to ::, then the next-hop is selected according to the local selection rules. This action only accepts packets with either a zero Segments Left value or no SRH at all, plus an inner IPv6 packet. Other matching packets are dropped. ๐Ÿšฎ
  • End.DT6 { table | vrftable } TABLEID โ€” decapsulate the inner IPv6 packet and forward it according to the specified lookup table. TABLEID is either a number or a string from /usr/share/iproute2/rt_tables or /etc/iproute2/rt_tables (has precedence if it exists). If vrftable is used, the argument must be a VRF device associated with the table id. And lowkey important: the VRF table associated with the table id must be configured with the VRF strict mode turned on (net.vrf.strict_mode=1) ๐Ÿ”ฅ. This action only accepts packets with either a zero Segments Left value or no SRH at all, plus an inner IPv6 packet. Other matching packets are dropped.
  • End.DT4 vrftable TABLEID โ€” decapsulate the inner IPv4 packet and forward it according to the specified lookup table. TABLEID is either a number or a string from /usr/share/iproute2/rt_tables or /etc/iproute2/rt_tables (has precedence if it exists). The argument must be a VRF device associated with the table id. Moreover, the VRF table associated with the table id must be configured with the VRF strict mode turned on (net.vrf.strict_mode=1). This action only accepts packets with either a zero Segments Left value or no SRH at all, plus an inner IPv4 packet. Other matching packets are dropped.
  • End.DT46 vrftable TABLEID โ€” decapsulate the inner IPv4 or IPv6 packet and forward it according to the specified lookup table. TABLEID is either a number or a string from /usr/share/iproute2/rt_tables or /etc/iproute2/rt_tables (has precedence if it exists). The argument must be a VRF device associated with the table id. Moreover, the VRF table associated with the table id must be configured with the VRF strict mode turned on (net.vrf.strict_mode=1). This action only accepts packets with either a zero Segments Left value or no SRH at all, plus an inner IPv4 or IPv6 packet. Other matching packets are dropped.
  • End.B6 srh segs SEGMENTS [ hmac KEYID ] โ€” insert the specified SRH immediately after the IPv6 header, update the DA with the first segment of the newly inserted SRH, then forward the resulting packet. The original SRH is not modified. This action only accepts packets with a non-zero Segments Left value. Other matching packets are dropped.
  • End.B6.Encaps srh segs SEGMENTS [ hmac KEYID ] โ€” regular SRv6 processing as an intermediate segment endpoint, and additionally encapsulate the matching packet within an outer IPv6 header followed by the specified SRH ๐ŸŽ€. The destination address of the outer IPv6 header is set to the first segment of the new SRH. The source address is set as described in ip-sr(8).

โœจ Flavors parameters

The flavors represent additional operations that can modify or extend a subset of the existing behaviors. It's giving bonus levels ๐ŸŽฎ

flavors OPERATION[,OPERATION] [ATTRIBUTES]

  OPERATION := { psp | usp | usd | next-csid }

  ATTRIBUTES := { KEY VALUE } [ ATTRIBUTES ]

  KEY := { lblen | nflen }
  • psp โ€” the Penultimate Segment Pop (PSP) copies the last SID from the SID List (carried by the outermost SRH) into the IPv6 Destination Address (DA) and removes (i.e. pops) the SRH from the IPv6 header. The PSP operation takes place only at a penultimate SR Segment Endpoint node (e.g., the Segment Left must be one) and does not happen at non-penultimate endpoint nodes. This flavor is currently only supported by the End behavior.
  • usp โ€” Ultimate Segment Pop of the SRH (not yet supported in kernel ๐Ÿ™ˆ)
  • usd โ€” Ultimate Segment Decapsulation (not yet supported in kernel ๐Ÿ™ˆ)
  • next-csid โ€” the NEXT-C-SID mechanism offers the possibility of encoding several SRv6 segments within a single 128 bit SID address ๐Ÿ‘‘. The NEXT-C-SID flavor can be configured to support user-provided Locator-Block and Locator-Node Function lengths. If Locator-Block and/or Locator-Node Function lengths are not provided by the user during configuration of an SRv6 End behavior instance with NEXT-C-SID flavor, the default value is 32-bit for Locator-Block and 16-bit for Locator-Node Function. Slay, defaults. โญ
  • lblen VALUE โ€” this sets the Locator-Block length for the NEXT-C-SID flavor. Two rules bestie, no exceptions: it has to be greater than 0, and it has to be evenly divisible by 8. Also it can only be used with NEXT-C-SID flavor, so don't try it anywhere else ๐Ÿ’…
  • nflen VALUE โ€” and this one sets the Locator-Node Function length for NEXT-C-SID flavors. Same energy: greater than 0, evenly divisible by 8, and NEXT-C-SID flavor only. ๐Ÿ”ฅ
  • ioam6 โ€” the whole IOAM6 situation, and she has layers:
    • freq K/N โ€” inject IOAM into K packets out of every N packets (default is 1/1).
    • mode inline โ€” just yeet the IOAM directly after the IPv6 header (this is the default mode).
    • mode encap โ€” instead, wrap the packet in an outer IPv6 header that carries the IOAM.
    • mode auto โ€” be smart about it: inline mode for local packets, encap mode for in-transit packets. It's giving โœจadaptableโœจ
    • tunsrc ADDRESS โ€” IPv6 address of the tunnel source (that's the outer header). Not used with inline mode. It's optional: if you don't give it, the tunnel source address gets picked automatically, no cap.
    • tundst ADDRESS โ€” IPv6 address of the tunnel destination (outer header again). Also not used with inline mode.
    • type IOAM6_TRACE_TYPE โ€” the list of IOAM data you want in the trace, expressed as a bitfield (24 bits, periodt).
    • ns IOAM6_NAMESPACE โ€” a numerical value representing an IOAM namespace. Go check ip-ioam(8) for the tea.
    • size IOAM6_TRACE_SIZE โ€” size, in octets, of the pre-allocated trace data block.
  • xfrm โ€” takes if_id IF_ID [ link_dev LINK_DEV ] ๐Ÿฆ‹

  • expires TIME (Linux 4.4+ only) โ€” the route gets deleted after the expires time. Heads up: only IPv6 is supported at present. ๐Ÿ˜ญ
  • ttl-propagate { enabled | disabled } โ€” controls whether TTL should be propagated from any encap into the un-encapsulated packet, and it overrides any global configuration. Only supported for MPLS at present.

๐Ÿ—‘๏ธ ip route delete

delete route

ip route del has the same arguments as ip route add, but their semantics are a little different, bestie.

Key values (to, tos, preference and table) select which route to delete. If optional attributes are present, ip verifies that they coincide with the attributes of the route to delete. And if no route with the given key and attributes was found, ip route del fails. ๐Ÿ’€

๐Ÿ‘€ ip route show

list routes

This command displays the contents of the routing tables, or the route(s) selected by some criteria.

  • to SELECTOR (default) โ€” only select routes from the given range of destinations. SELECTOR is made of an optional modifier (root, match or exact) plus a prefix.
    • root PREFIX selects routes with prefixes not shorter than PREFIX. For example root 0/0 selects the entire routing table. ๐Ÿซถ
    • match PREFIX selects routes with prefixes not longer than PREFIX. For example match 10.0/16 selects 10.0/16, 10/8 and 0/0, but it does not select 10.1/16 and 10.0.0/24. So specific, so picky ๐Ÿ’…
    • exact PREFIX (or just PREFIX) selects routes with this exact prefix.
    • If none of these options are present, ip assumes root 0/0, i.e. it lists the entire table.
  • tos TOS
  • dsfield TOS โ€” only select routes with the given TOS.
  • table TABLEID โ€” show the routes from this table(s). The default setting is to show table main. TABLEID may either be the ID of a real table or one of these special values:
    • all โ€” list all of the tables.
    • cache โ€” dump the routing cache.
  • vrf NAME โ€” show the routes for the table associated with the vrf name.
  • cloned โ€” that's it, that's the whole thing ๐Ÿ’–
  • cached โ€” list cloned routes, i.e. routes which were dynamically forked from other routes because some route attribute (f.e. MTU) was updated. Actually, it is equivalent to table cache.
  • from SELECTOR โ€” same syntax as for to, but it binds the source address range rather than destinations. Note that the from option only works with cloned routes.
  • protocol RTPROTO โ€” only list routes of this protocol.
  • scope SCOPE_VAL โ€” only list routes with this scope.
  • type TYPE โ€” only list routes of this type.
  • dev NAME โ€” only list routes going via this device.
  • via [ FAMILY ] PREFIX โ€” only list routes going via the nexthop routers selected by PREFIX.
  • src PREFIX โ€” only list routes with preferred source addresses selected by PREFIX.
  • realm REALMID
  • realms FROMREALM/TOREALM โ€” only list routes with these realms.

๐Ÿงผ ip route flush

flush routing tables

This command flushes routes selected by some criteria.

The arguments have the same syntax and semantics as the arguments of ip route show, but routing tables are not listed โ€” they're purged. ๐Ÿ˜ค The only difference is the default action: show dumps all the IP main routing table, but flush prints the helper page.

With the -statistics option, the command becomes verbose. It prints out the number of deleted routes and the number of rounds made to flush the routing table. If the option is given twice, ip route flush also dumps all the deleted routes in the format described in the previous subsection. Iconic behaviour honestly.

๐ŸŽฏ ip route get

get a single route

This command gets a single route to a destination and prints its contents exactly as the kernel sees it. No filter, no edit, raw truth โœจ

  • fibmatch โ€” return full fib lookup matched route. Default is to return the resolved dst entry.
  • to ADDRESS (default) โ€” the destination address.
  • from ADDRESS โ€” the source address.
  • tos TOS
  • dsfield TOS โ€” the Type Of Service.
  • iif NAME โ€” the device from which this packet is expected to arrive.
  • oif NAME โ€” force the output device on which this packet will be routed.
  • mark MARK โ€” the firewall mark (fwmark).
  • vrf NAME โ€” force the vrf device on which this packet will be routed.
  • uid NUMBER โ€” the user ID as seen by the route lookup.
  • ipproto PROTOCOL โ€” ip protocol as seen by the route lookup.
  • sport NUMBER โ€” source port as seen by the route lookup.
  • dport NUMBER โ€” destination port as seen by the route lookup.
  • connected โ€” if no source address (option from) was given, relookup the route with the source set to the preferred address received from the first lookup. If policy routing is used, it may be a different route. Plot twist ๐ŸŒˆ
  • flowlabel FLOWLABEL โ€” ipv6 flow label as seen by the route lookup.
Note that this operation is not equivalent to ip route show. show shows existing routes. get resolves them and creates new clones if necessary. Essentially, get is equivalent to sending a packet along this path.

If the iif argument is not given, the kernel creates a route to output packets towards the requested destination. This is equivalent to pinging the destination with a subsequent ip route ls cache, however, no packets are actually sent. With the iif argument, the kernel pretends that a packet arrived from this interface and searches for a path to forward the packet.

๐Ÿ’พ ip route save

save routing table information to stdout

This command behaves like ip route show except that the output is raw data suitable for passing to ip route restore. Snapshot tingz ๐Ÿ“ธ

โ™ป๏ธ ip route restore

restore routing table information from stdin

This command expects to read a data stream as returned from ip route save. It will attempt to restore the routing table information exactly as it was at the time of the save, so any translation of information in the stream (such as device indexes) must be done first. Any existing routes are left unchanged. Any routes specified in the data stream that already exist in the table will be ignored. She said "no duplicates, we're not doing that" ๐Ÿ’…

๐Ÿ“ NOTES

Starting with Linux kernel version 3.6, there is no routing cache for IPv4 anymore. Hence ip route show cached will never print any entries on systems with this or newer kernel versions. Sad for the cache girlies, but that's the reality ๐Ÿ˜ญ

๐Ÿ’– EXAMPLES ๐Ÿ’–

Bestie, this is the part where we stop yapping and start doing. Copy these, run these, live these. โœจ


  • ip ro โ€” shows you every single route entry chillin' in the kernel.
ip ro

Show all route entries in the kernel.

  • ip route add default via 192.168.1.1 dev eth0 โ€” drops a default route (aka the "for literally all addresses" route ๐Ÿ’…) through the local gateway 192.168.1.1, which you can reach on device eth0.
ip route add default via 192.168.1.1 dev eth0

Adds a default route (for all addresses) via the local gateway 192.168.1.1 that can be reached on device eth0.

  • ip route add 10.1.1.0/30 encap mpls 200/300 via 10.1.1.1 dev eth0 โ€” adds an ipv4 route with mpls encapsulation attributes attached to it.
ip route add 10.1.1.0/30 encap mpls 200/300 via 10.1.1.1 dev eth0

Adds an ipv4 route with mpls encapsulation attributes attached to it.

  • ip -6 route add 2001:db8:1::/64 encap seg6 mode encap segs 2001:db8:42::1,2001:db8:ffff::2 dev eth0 โ€” adds an IPv6 route with SRv6 encapsulation and two segments attached.
ip -6 route add 2001:db8:1::/64 encap seg6 mode encap segs 2001:db8:42::1,2001:db8:ffff::2 dev eth0

Adds an IPv6 route with SRv6 encapsulation and two segments attached.

  • ip -6 route add 2001:db8:1::/64 encap seg6local action End.DT46 vrftable 100 dev vrf100 โ€” adds an IPv6 route with SRv6 decapsulation and forward with lookup in VRF table.
ip -6 route add 2001:db8:1::/64 encap seg6local action End.DT46 vrftable 100 dev vrf100

Adds an IPv6 route with SRv6 decapsulation and forward with lookup in VRF table.

  • ip -6 route add 2001:db8:1::/64 encap seg6local action End flavors psp dev eth0 โ€” adds an IPv6 route with SRv6 End behavior with the psp flavor enabled.
ip -6 route add 2001:db8:1::/64 encap seg6local action End flavors psp dev eth0

Adds an IPv6 route with SRv6 End behavior with psp flavor enabled.

  • ip -6 route add 2001:db8:1::/64 encap seg6local action End flavors next-csid dev eth0 โ€” adds an IPv6 route with SRv6 End behavior with the next-csid flavor enabled.
ip -6 route add 2001:db8:1::/64 encap seg6local action End flavors next-csid dev eth0

Adds an IPv6 route with SRv6 End behavior with next-csid flavor enabled.

  • ip -6 route add 2001:db8:1::/64 encap seg6local action End flavors next-csid lblen 48 nflen 16 dev eth0 โ€” adds an IPv6 route with SRv6 End behavior, next-csid flavor enabled, and user-provided Locator-Block and Locator-Node Function lengths. Very extra, very cute. ๐ŸŽ€
ip -6 route add 2001:db8:1::/64 encap seg6local action End flavors next-csid lblen 48 nflen 16 dev eth0

Adds an IPv6 route with SRv6 End behavior with next-csid flavor enabled and user-provided Locator-Block and Locator-Node Function lengths.

  • ip -6 route add 2001:db8:1::/64 encap ioam6 freq 2/5 mode encap tundst 2001:db8:42::1 trace prealloc type 0x800000 ns 1 size 12 dev eth0 โ€” adds an IPv6 route with an IOAM Pre-allocated Trace encapsulation (ip6ip6) that only includes the hop limit and the node id, configured for the IOAM namespace 1 and a pre-allocated data block of 12 octets (which will be injected in 2 packets every 5 packets).
ip -6 route add 2001:db8:1::/64 encap ioam6 freq 2/5 mode encap tundst 2001:db8:42::1 trace prealloc type 0x800000 ns 1 size 12 dev eth0

Adds an IPv6 route with an IOAM Pre-allocated Trace encapsulation (ip6ip6) that only includes the hop limit and the node id, configured for the IOAM namespace 1 and a pre-allocated data block of 12 octets (will be injected in 2 packets every 5 packets).

  • ip route add 10.1.1.0/30 nhid 10 โ€” adds an ipv4 route using a nexthop object with id 10.
ip route add 10.1.1.0/30 nhid 10

Adds an ipv4 route using nexthop object with id 10.


๐Ÿ‘€ SEE ALSO ๐Ÿ‘€


๐Ÿซถ AUTHOR ๐Ÿซถ

Original Manpage by Michail Litvak <mci@owl.openwall.com>


okay that's the whole page bestie, you ate that fr fr ๐Ÿ’…โœจ go configure some routes and be the main character of your own network. This one's from the iproute2 era, dated 13 Dec 2012, and lives under the name IP-ROUTE(8) โ€” iconic, historic, obsessed. ๐ŸŒˆ๐Ÿ‘‘

๐Ÿ“ฆ where this page comes from