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 anEHOSTUNREACHerror back. brutal but informative ๐blackholeโ also unreachable, but make it โจsilentโจ. packets are discarded silently, no ICMP, nothing. local senders get anEINVALerror. 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 anEACCESerror.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 anENETUNREACHerror.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 theviaattribute.
โ ๏ธ 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 tolocalwith 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_tablesor/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. ifTYPEis omitted, ip assumes typeunicast. other values ofTYPEare listed above.PREFIXis 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 specialPREFIXofdefaultโ which is equivalent to IP0/0or to IPv6::/0. ๐tos TOSdsfield 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.TOSis either an 8 bit hexadecimal number or an identifier from/usr/share/iproute2/rt_dsfieldor/etc/iproute2/rt_dsfield(has precedence if exists).metric NUMBERpreference NUMBERโ the preference value of the route.NUMBERis an arbitrary 32bit number, where routes with lower values are preferred. lowkey competitive.table TABLEIDโ the table to add this route to.TABLEIDmay be a number or a string from/usr/share/iproute2/rt_tablesor/etc/iproute2/rt_tables(has precedence if exists). if this parameter is omitted, ip assumes themaintable, with the exception oflocal,broadcastandnatroutes, which are put into thelocaltable 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 familyFAMILY. 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.REALMIDmay be a number or a string from/usr/share/iproute2/rt_realmsor/etc/iproute2/rt_realms(has precedence if exists).mtu MTUmtu lock MTUโ the MTU along the path to the destination. if the modifierlockis not used, the MTU may be updated by the kernel due to Path MTU Discovery. if the modifierlockis 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 ofs,secorsecsis used you're specifying seconds, andms,msecormsecsmeans milliseconds.rttvar TIME(Linux 2.3.15+ only) โ the initial RTT variance estimate. values are specified as withrttabove.rto_min TIME(Linux 2.6.23+ only) โ the minimum TCP Retransmission TimeOut to use when communicating with this destination. values are specified as withrttabove.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. ๐initrwndNUMBER (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 is0, and0means "just use the Slow Start value, bestie."featuresFEATURES โ turn per-route features on or off โจ. The available features areecnandtcp_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,ecngets used anyway โ even if thenet.ipv4.tcp_ecnsysctl is set to0. 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.
quickackBOOL (Linux 3.11+ only) โ enable or disable quick ack for connections to this destination ๐fastopen_no_cookieBOOL (Linux 4.15+ only) โ enable TCP Fastopen without a cookie for connections to this destination ๐ช๐ซcongctlNAME (Linux 3.20+ only)congctl lockNAME (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 thelockmodifier, an application can still overwrite the suggested congestion control algorithm for that destination โ lowkey rude but allowed ๐. If you do use thelockmodifier, 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 ๐advmssNUMBER (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.)reorderingNUMBER (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 variablenet/ipv4/tcp_reordering๐nexthopNEXTHOP โ 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.devNAME โ is the output device.weightNUMBER โ 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 ๐
scopeSCOPE_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_scopesor/etc/iproute2/rt_scopes(which has precedence if it exists). If you omit this parameter,ipassumesscope globalfor all gatewayed unicast routes,scope linkfor direct unicast and broadcast routes, andscope hostfor local routes. It just knows ๐protocolRTPROTO โ the routing protocol identifier of this route ๐. RTPROTO may be a number or a string from/usr/share/iproute2/rt_protosor/etc/iproute2/rt_protos(has precedence if exists). If the routing protocol ID is not given,ipassumes protocolbootโ 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 ๐prefPREF โ 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 prioritymediumโ the route has a default priorityhighโ the route has a highest priority
nhidID โ use nexthop object with given id as nexthop specification ๐encapENCAPTYPE ENCAPHDR โ attach tunnel encapsulation attributes to this route ๐ฆ
ENCAPTYPE is a string specifying the supported encapsulation type. Namely:
mplsโ encapsulation type MPLSipโ IP encapsulation (Geneve,GRE,VXLAN, ...)bpfโ Execution of BPF programseg6โ encapsulation type IPv6 Segment Routingseg6localโ local SRv6 segment processingioam6โ encapsulation type IPv6 IOAMxfrmโ encapsulation type XFRM
ENCAPHDR is a set of encapsulation attributes specific to the ENCAPTYPE โจ
mpls- MPLSLABEL โ mpls label stack with labels separated by
/ ttlTTL โ TTL to use for MPLS header or0to inherit from IP header
- MPLSLABEL โ mpls label stack with labels separated by
ipidTUNNEL_ID โ Tunnel ID (for example VNI in VXLAN tunnel)dstREMOTE_IP โ Outer header destination IP address (IPv4 or IPv6)srcSRC โ Outer header source IP address (IPv4 or IPv6)tosTOS โ Outer header TOSttlTTL โ Outer header TTLkeyโ Outer header flags with key in GRE tunnelcsumโ Outer header flags with csum in GRE tunnelseqโ 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 is1, and DIR and HWID are used when VERSION is2.
bpfinPROG โ BPF program to execute for incoming packetsoutPROG โ BPF program to execute for outgoing packetsxmitPROG โ BPF program to execute for transmitted packetsheadroomSIZE โ Size of header BPF program will attach (xmit)
seg6mode inlineโ Directly insert Segment Routing Header after IPv6 headermode encapโ Encapsulate packet in an outer IPv6 header with SRHmode 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 SRHmode 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. Seeip-sr(8). ๐lookup TABLEIDโ the table for the post-encap SID route lookup, like, the lookup for the route of the first SID.TABLEIDis either a number or a string pulled from/usr/share/iproute2/rt_tablesor/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 anEndbehavior 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 anEnd.Xbehavior 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.TABLEIDis either a number or a string from/usr/share/iproute2/rt_tablesor/etc/iproute2/rt_tables(has precedence if it exists). Ifvrftableis 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.TABLEIDis either a number or a string from/usr/share/iproute2/rt_tablesor/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.TABLEIDis either a number or a string from/usr/share/iproute2/rt_tablesor/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 inip-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 theEndbehavior.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 is1/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 checkip-ioam(8)for the tea.size IOAM6_TRACE_SIZEโ size, in octets, of the pre-allocated trace data block.
xfrmโ takesif_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.SELECTORis made of an optional modifier (root,matchorexact) plus a prefix.root PREFIXselects routes with prefixes not shorter thanPREFIX. For exampleroot 0/0selects the entire routing table. ๐ซถmatch PREFIXselects routes with prefixes not longer thanPREFIX. For examplematch 10.0/16selects10.0/16,10/8and0/0, but it does not select10.1/16and10.0.0/24. So specific, so picky ๐exact PREFIX(or justPREFIX) selects routes with this exact prefix.- If none of these options are present,
ipassumesroot 0/0, i.e. it lists the entire table.
tos TOSdsfield TOSโ only select routes with the given TOS.table TABLEIDโ show the routes from this table(s). The default setting is to show tablemain.TABLEIDmay 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 totable cache.from SELECTORโ same syntax as forto, but it binds the source address range rather than destinations. Note that thefromoption 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 byPREFIX.src PREFIXโ only list routes with preferred source addresses selected byPREFIX.realm REALMIDrealms 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 TOSdsfield 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 (optionfrom) 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 toip route show.showshows existing routes.getresolves them and creates new clones if necessary. Essentially,getis 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 gateway192.168.1.1, which you can reach on deviceeth0.
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 thepspflavor 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 thenext-csidflavor 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-csidflavor 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 namespace1and 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 id10.
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
- arch rolling: iproute2 7.3.0-1 ยท GPL-2.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms