ip (iproute2) (5/6)
Part 5 of the ip command covers advanced kernel objects used daily in data center and cloud networking: IPv6 address labels, UDP tunnels (FOU/GUE), IOAM telemetry, L2TP, MACsec, MPTCP, multicast routes, per-device netconf, nexthop objects and ARP table tuning (ntable).
21.1 Why is it used?
- All these objects change Linux kernel tables directly, so they exist only on Linux; Windows and macOS have no ip command.
- addrlabel controls which IPv6 source address the kernel picks when a host has many addresses.
- fou/gue carry tunnel packets inside UDP so they pass NAT and firewalls; ioam adds IPv6 in-band telemetry.
- l2tp, macsec and mptcp build L2 tunnels, L2 encryption and multipath TCP, but need kernel support.
- nexthop objects let thousands of routes share one gateway object, with ECMP groups, resilient buckets and blackholes.
- Lab: one privileged netshoot container with namespaces h1, h2 (hosts) and r1, r2 (routers) on 192.168.41.0/24.
| Object | What it does | Lab result |
|---|---|---|
| addrlabel | IPv6 source address selection labels (RFC 3484) | Real |
| fou / gue | UDP receive ports for tunnel encapsulation | Real: IPIP over FOU ping |
| ioam | IPv6 In-situ OAM namespaces and schemas | Real |
| l2tp | Static L2TPv3 tunnels and sessions | Kernel: CONFIG_L2TP not set |
| macsec | 802.1AE L2 encryption device + SAs | Kernel: CONFIG_MACSEC not set |
| mptcp | MPTCP path manager endpoints and limits | Kernel: CONFIG_MPTCP not set |
| mroute | Multicast routing cache (read-only) | Real, empty |
| netconf | Per-device forwarding, rp_filter ... | Real |
| nexthop | Shared gateway objects, groups, buckets | Real |
| ntable | Neighbour (ARP) table parameters | Real |
21.2 ip addrlabel: IPv6 source address labels
- With several IPv6 addresses, the kernel chooses the source by RFC 3484 rules; a source whose label matches the destination's label is preferred.
- list shows the kernel's default label table; add prefix ... label N creates a rule; dev limits the rule to one interface.
- del removes one entry, flush clears all labels.
ip addrlabel listip addrlabel add prefix 2001:db8::/32 \ label 100ip addrlabel add prefix 2001:db8:41::/48 \ dev eth0 label 101ip addrlabel add prefix ::ffff:0:0/96 label 4ip addrlabel list | grep 2001:db8ip addrlabel del prefix 2001:db8:41::/48 \ dev eth0 label 101ip addrlabel flush$ ip addrlabel listprefix ::1/128 label 0prefix ::/96 label 3prefix ::ffff:0.0.0.0/96 label 4prefix 2001::/32 label 6prefix 2002::/16 label 2prefix fc00::/7 label 5prefix ::/0 label 1$ ip addrlabel list | grep 2001:db8prefix 2001:db8:41::/48 dev eth0 label 101prefix 2001:db8::/32 label 10021.3 ip fou / gue: tunnels inside UDP
- Foo-over-UDP wraps a tunnel packet (here IPIP, ipproto 4) inside UDP so it can cross NAT and firewalls.
- ip fou add port 5555 ipproto 4 opens a receive port; the ipip1 link uses encap fou with encap-dport 5555.
- gue = Generic UDP Encapsulation: the protocol is carried in a GUE header instead of being fixed per port.
- local / peer / peer_port / dev bind a receive port to specific endpoints; show lists ports, del removes one.
- The fou module (CONFIG_NET_FOU=m) had to be loaded in the lab.
- Step 1
1.h1 pings 10.41.1.2 via ipip1
- Step 2
2.Kernel wraps it as IPIP (inner 10.41.1.1 -> 10.41.1.2)
- Step 3
3.FOU adds outer UDP: 192.168.41.10 -> 192.168.41.20:5555
- Step 4
4.Packet crosses the switch br0 (192.168.41.0/24)
- Step 5
5.h2 fou port 5555 strips UDP, IPIP goes to ipip1
- Step 6
6.Reply returns to h1 the same way
tcpdump on eth0 shows only UDP port 5555 packets, length 84
ip fou add port 5555 ipproto 4ip link add ipip1 type ipip \ remote 192.168.41.20 local 192.168.41.10 \ encap fou encap-sport auto encap-dport 5555ping -c 2 10.41.1.2tcpdump -ni eth0 -c 2 udp port 5555ip fou add port 6666 gueip fou add port 7777 ipproto 47 \ local 192.168.41.10 peer 192.168.41.20 \ peer_port 7777ip fou add port 8888 ipproto 4 \ local 192.168.41.10 dev eth0ip fou showip fou del port 6666$ ping -c 2 10.41.1.264 bytes from 10.41.1.2: icmp_seq=1 ttl=6464 bytes from 10.41.1.2: icmp_seq=2 ttl=642 packets transmitted, 2 received, 0% packet loss$ tcpdump -ni eth0 -c 2 udp port 5555IP 192.168.41.10.46431 > 192.168.41.20.5555: UDP, length 84IP 192.168.41.20.46431 > 192.168.41.10.5555: UDP, length 84$ ip fou showport 8888 ipproto 4 local 192.168.41.10 dev eth0port 7777 ipproto 47 local 192.168.41.10 peer 192.168.41.20 peer_port 7777port 6666 gueport 5555 ipproto 421.4 ip ioam: IPv6 In-situ OAM
- IOAM records telemetry (node data) inside IPv6 packets as they travel.
- namespace add N data X [wide Y] creates a namespace; schema add creates a schema; namespace set N schema S links them.
- schema none unlinks; del removes namespaces and schemas.
ip ioam namespace add 1 data 0xdeadbeefip ioam namespace add 2 data 0x41 \ wide 0xcafec0caf00dc0deip ioam schema add 7 lab-schemaip ioam namespace set 1 schema 7ip ioam namespace showip ioam schema showip ioam namespace set 1 schema noneip ioam namespace del 2ip ioam schema del 7$ ip ioam namespace shownamespace 1 [schema 7], data 0xdeadbeefnamespace 2, data 0x00000041, wide 0xcafec0caf00dc0de$ ip ioam schema showschema 7 [namespace 1], data: 6c 61 62 2d 73 63 68 65 6d 61 00 0021.5 L2TP, MACsec, MPTCP: kernel support first
- Check the kernel config before blaming the command: in the Docker Desktop WSL kernel, L2TP, MACSEC and MPTCP are not set.
- Then ip l2tp and ip mptcp fail with 'No such file or directory' and macsec with 'Unknown device type'.
- On a normal distro kernel these are usually modules (l2tp_eth, macsec, MPTCP built in).
zcat /proc/config.gz | grep -E \ "CONFIG_(L2TP|MACSEC|MPTCP|NET_FOU|IP_MROUTE)=?"ip l2tp add tunnel tunnel_id 3000 \ peer_tunnel_id 4000 encap udp \ local 192.168.41.10 remote 192.168.41.20 \ udp_sport 5000 udp_dport 6000ip link add link eth0 macsec0 type macsec \ port 11 encrypt onip mptcp endpoint add 192.168.41.10 \ dev eth0 subflowCONFIG_IP_MROUTE=yCONFIG_NET_FOU=m# CONFIG_MPTCP is not set# CONFIG_L2TP is not set# CONFIG_MACSEC is not set$ ip l2tp add tunnel ...RTNETLINK answers: No such file or directoryError talking to the kernel$ ip link add ... type macsec ...Error: Unknown device type.$ ip mptcp endpoint add ...RTNETLINK answers: No such file or directory| Tool | Key options | Meaning |
|---|---|---|
| l2tp add tunnel | tunnel_id / peer_tunnel_id, local / remote | Static (unmanaged) L2TPv3 tunnel, IDs cross-match the peer |
| l2tp add tunnel | encap udp | ip, udp_sport / udp_dport | UDP is NAT friendly, IP has less overhead |
| l2tp add session | session_id / peer_session_id, name, cookie, seq | Session inside a tunnel = an l2tpeth interface |
| type macsec | port / sci, cipher gcm-aes-128|256|xpn, encrypt on|off | SCI = MAC + port; encrypt off = authentication only |
| type macsec | replay on window 32, validate strict|check|disabled, offload | Replay protection, frame validation, HW offload |
| ip macsec | tx sa 0 pn 1024 on key 01 KEY, rx port ... address MAC | TX SA has the key; RX channel + RX SA per peer |
| ip mptcp endpoint | subflow, signal, backup, fullmesh, id | Extra paths: create subflows or announce addresses |
| ip mptcp limits | set subflow 4, add_addr_accepted 4 | Max subflows / accepted ADD_ADDR per connection |
ip l2tp add tunnel tunnel_id 3000 peer_tunnel_id 4000 \ encap udp local 192.168.41.10 remote 192.168.41.20 \ udp_sport 5000 udp_dport 6000ip l2tp add session tunnel_id 3000 session_id 1000 \ peer_session_id 2000 name l2tp0ip l2tp show tunnel tunnel_id 3000ip l2tp show session tunnel_id 3000ip link set l2tpeth0 up mtu 1488ip l2tp del session tunnel_id 3000 session_id 1000ip l2tp del tunnel tunnel_id 3000ip link add link eth0 macsec0 type macsec port 11 encrypt onip macsec add macsec0 tx sa 0 pn 1024 on key 01 KEYip macsec add macsec0 rx port 1234 address MACip macsec add macsec0 rx port 1234 address MAC sa 0 pn 1 on key 00 KEYip macsec show macsec021.6 ip mroute and ip netconf: read-only status
- ip mroute shows the multicast routing cache; it is read-only (a multicast daemon such as pimd fills it). In the lab it is empty.
- iif filters by input interface; a prefix can be written directly (ip mroute show 239.1.1.1). show to / from failed to parse in iproute2-6.9.0.
- ip netconf shows per-device settings: forwarding is off on host h1 and on on router r1.
ip mroute showip mroute show table allip -6 mroute showip mroute show iif eth0cat /proc/net/ip_mr_vif$ ip mroute show$ ip mroute show table all$ ip -6 mroute show$ cat /proc/net/ip_mr_vifInterface BytesIn PktsIn BytesOut PktsOut Flagsip netconf show dev eth0 # h1ip netconf show dev eth0 # r1ip -6 netconf show dev eth0 # r1ip netconf show | head -3 # r1h1$ ip netconf show dev eth0inet eth0 forwarding off rp_filter off mc_forwarding off proxy_neigh offr1$ ip netconf show dev eth0inet eth0 forwarding on rp_filter off mc_forwarding off proxy_neigh offr1$ ip -6 netconf show dev eth0inet6 eth0 forwarding off mc_forwarding off proxy_neigh off ignore_routes_with_linkdown off21.7 ip nexthop: shared gateway objects
- In a normal route the gateway is inside the route; with nexthop objects the gateway is a separate object shared by many routes (route ... nhid N).
- group 1/2 = ECMP across nexthops 1 and 2; group 1,5/2,11 = weighted (5:11).
- type resilient buckets 8 idle_timer 60: flows are mapped to buckets; on failure only that nexthop's buckets move.
- blackhole drops traffic (ping says 'Invalid argument'); replace changes a gateway once for all routes using it.
- Other options: via inet6, onlink, encap mpls, fdb nexthops, show vrf / master filters.
- Step 1
1.ip nexthop add id 1 via r1, id 2 via r2
- Step 2
2.id 3 group 1/2; route 10.10.0.20/32 nhid 3
- Step 3
3.Kernel hashes each flow (addresses, ports)
- Step 4
4.Flow sport 1000 -> r1 (192.168.41.1)
- Step 5
5.Flow sport 1003 -> r2 (192.168.41.2)
- Step 6
6.Both reach the app server 10.10.0.20
One flow always uses one nexthop; only different flows spread
ip nexthop add id 1 via 192.168.41.1 dev eth0ip nexthop add id 2 via 192.168.41.2 dev eth0ip nexthop add id 3 group 1/2ip route add 10.10.0.20/32 nhid 3ip route get 10.10.0.20 ipproto tcp \ sport 1000 dport 80ip route get 10.10.0.20 ipproto tcp \ sport 1003 dport 80ip nexthop add id 4 group 1,5/2,11ip nexthop add id 10 group 1/2 \ type resilient buckets 8 idle_timer 60ip nexthop add id 99 blackholeip route add 10.99.0.0/24 nhid 99ip nexthop replace id 1 via 192.168.41.20 \ dev eth0$ ip route show 10.10.0.2010.10.0.20 nhid 3 nexthop via 192.168.41.1 dev eth0 weight 1 nexthop via 192.168.41.2 dev eth0 weight 1$ ip route get ... sport 1000 dport 8010.10.0.20 via 192.168.41.1 dev eth0 src 192.168.41.10$ ip route get ... sport 1003 dport 8010.10.0.20 via 192.168.41.2 dev eth0 src 192.168.41.10$ ping -c 1 -W 1 10.99.0.5ping: connect: Invalid argument$ ip nexthop get id 1id 1 via 192.168.41.20 dev eth0 scope linkip nexthop showip nexthop show groupsip nexthop show id 3ip nexthop show dev eth0ip nexthop bucket show id 10ip nexthop bucket get id 10 index 5ip nexthop del id 99ip nexthop fluship route show 10.10.0.20$ ip nexthop showid 1 via 192.168.41.1 dev eth0 scope linkid 2 via 192.168.41.2 dev eth0 scope linkid 3 group 1/2id 4 group 1,5/2,11id 10 group 1/2 type resilient buckets 8 idle_timer 60id 99 blackhole$ ip nexthop bucket show id 10id 10 index 0 idle_time 0.13 nhid 2id 10 index 3 idle_time 0.13 nhid 2id 10 index 4 idle_time 0.13 nhid 1id 10 index 7 idle_time 0.13 nhid 1$ ip nexthop bucket get id 10 index 5id 10 index 5 idle_time 0.14 nhid 1$ ip nexthop flushFlushed 5 nexthops$ ip route show 10.10.0.20(empty: the route is gone too)21.8 ip ntable: ARP table tuning
- ntable shows and changes neighbour table parameters; name arp_cache is the IPv4 ARP table.
- Per-device: reachable, base_reachable, retrans, gc_stale, queue, probes. Without dev: global thresh1/2/3 and gc_int.
- thresh1 = below this no GC runs, thresh2 = soft max, thresh3 = hard max; locktime = minimum time before an entry is replaced.
ip ntable show name arp_cache dev eth0ip ntable show name arp_cache | head -6ip ntable change name arp_cache dev eth0 \ queue 8ip ntable change name arp_cache dev eth0 \ base_reachable 60000ip ntable show name arp_cache dev eth0$ ip ntable show name arp_cache dev eth0inet arp_cache dev eth0 refcnt 4 reachable 29036 base_reachable 30000 retrans 1000 gc_stale 60000 delay_probe 5000 queue 101 app_probes 0 ucast_probes 3 mcast_probes 3 anycast_delay 1000 proxy_delay 800 proxy_queue 64 locktime 1000$ ip ntable show name arp_cache | head -6inet arp_cache thresh1 128 thresh2 512 thresh3 1024 gc_int 30000$ ip ntable show name arp_cache dev eth0 # after changeinet arp_cache dev eth0 refcnt 4 reachable 39832 base_reachable 60000 retrans 1000 gc_stale 60000 delay_probe 5000 queue 821.9 Common mistakes
- Thinking FOU / L2TP / IPIP tunnels are secure: they only encapsulate; use MACsec (L2) or IPsec via ip xfrm (L3) for encryption.
- Expecting one TCP connection to alternate between ECMP nexthops: the kernel hashes per flow.
- Blaming the command when the feature is missing from the kernel: check /proc/config.gz first.
- Deleting a nexthop or flushing: routes using it disappear too.
21.10 Interview tips
- Why nexthop objects: defined once and shared by thousands of routes; one replace updates all; resilient groups move only the failed nexthop's buckets.
- ECMP is per-flow hashing, not per-packet, to avoid reordering.
- FOU/GUE = encapsulation for NAT traversal, not encryption.
- ip netconf forwarding on/off quickly tells you whether a box routes.
- Know addrlabel = RFC 3484 (now RFC 6724) source address selection.