TC-MIRRED(8)
๐ฆ TC-MIRRED(8) ๐ฆ
okay bestie, this is the tc-mirred page, aka the mirror/redirect action in tc(8) ๐ It's the thing that lets you copy or steal packets as they come in, and it's lowkey iconic ๐
โจ NAME โจ
mirred - mirror/redirect action ๐ง
๐ SYNOPSIS ๐
tc ... action mirred DIRECTION ACTION [ index INDEX ] TARGET
DIRECTION := { ingress | egress }
TARGET := { DEV | BLOCK }
DEV := dev DEVICENAME
BLOCK := blockid BLOCKID
ACTION := { mirror | redirect }
๐ธ DESCRIPTION ๐ธ
okay so the mirred action lets you do packet mirroring (copying) or redirecting (stealing) whatever packet it receives ๐ฅ Mirroring is what people call Switch Port Analyzer (SPAN), and it's super popular for analyzing and/or debugging flows ๐
when you mirror to a tc block, the packet gets copied to every port in the block EXCEPT the port it came in on (only if that port is actually part of the tc block) โจ Redirecting is basically the same vibe, except it mirrors to the first N - 1 ports in the block and then redirects to the last one ๐ The port the packet arrived on is never mirrored or redirected to, so don't even try ๐ โโ๏ธ
๐ OPTIONS ๐
ingress/egressโ pick the direction the packet shows up in on the destination interface ๐ฆmirror/redirectโ decide whether the packet gets copied (mirror) or moved (redirect) to the destination interface or block ๐index INDEXโ give this action its own unique ID instead of letting the kernel pick one for you ๐งINDEXis a 32bit unsigned integer that has to be greater than zerodev DEVICENAMEโ the network interface you want to redirect or mirror to ๐blockid BLOCKIDโ the tc block you want to redirect or mirror to โญ
๐ EXAMPLES ๐
okay here are the examples, bestie, they're giving practical energy ๐ซถ
Limit ingress bandwidth on eth0 to 1mbit/s, and redirect the exceeding traffic to lo for debugging purposes ๐
# tc qdisc add dev eth0 handle ffff: clsact
# tc filter add dev eth0 ingress u32 \
match u32 0 0 \
action police rate 1mbit burst 100k conform-exceed pipe \
action mirred egress redirect dev lo
Mirror all incoming ICMP packets on eth0 to a dummy interface so you can examine them with e.g. tcpdump ๐
# ip link add dummy0 type dummy
# ip link set dummy0 up
# tc qdisc add dev eth0 handle ffff: clsact
# tc filter add dev eth0 ingress protocol ip \
u32 match ip protocol 1 0xff \
action mirred egress mirror dev dummy0
Using an ifb interface, you can send ingress traffic through an instance of sfq ๐งโโ๏ธโจ
# modprobe ifb
# ip link set ifb0 up
# tc qdisc add dev ifb0 root sfq
# tc qdisc add dev eth0 handle ffff: clsact
# tc filter add dev eth0 ingress u32 \
match u32 0 0 \
action mirred egress redirect dev ifb0
๐ญ LIMITATIONS ๐ญ
the kernel caps nesting at four levels so nesting loops can't happen ๐
โ ๏ธ Do not redirect from one IFB device to another. IFB is a very specialized case of packet redirecting device, and redirecting from ifbX->ifbY will cause ALL packets to be dropped. literally the worst, don't do it ๐
๐ SEE ALSO ๐
that's a wrap, bestie! ๐ Source: iproute2, version dated 11 Jan 2015 (Linux) ๐ซถโจ now go mirror something iconic ๐๐
๐ฆ where this page comes from
- alpine 3.22: iproute2-doc 6.15.0-r0 ยท GPL-2.0-or-later
- alpine 3.23: iproute2-doc 6.17.0-r0 ยท GPL-2.0-or-later
- alpine 3.24: iproute2-doc 7.0.0-r0 ยท GPL-2.0-or-later
- arch rolling: iproute2 7.2.0-1
- arch rolling: iproute2 7.3.0-1 ยท GPL-2.0-or-later
- centos-stream 10: iproute-tc 7.0.0-2.el10 ยท GPL-2.0-or-later
- centos-stream 9: iproute-tc 6.17.0-3.el9 ยท GPL-2.0-or-later
- debian trixie: iproute2 6.15.0-1 ยท GPL-2.0-only
- fedora 43: iproute-tc 6.14.0-2.fc43 ยท GPL-2.0-or-later
- fedora 44: iproute-tc 6.17.0-2.fc44 ยท GPL-2.0-or-later
- nixos 26.05: iproute2 7.0.0
- nixpkgs unstable: iproute2 7.2.0
- opensuse-leap 16.0: iproute2 6.12-160000.4.1 ยท GPL-2.0-only
- opensuse-leap 16.0: iproute2 6.12-160000.4.1 ยท GPL-2.0-only
- opensuse-leap 16.0: iproute2 6.12-160000.4.1 ยท GPL-2.0-only
- opensuse-leap 16.0: iproute2 6.12-160000.4.1 ยท GPL-2.0-only
- ubuntu questing: iproute2 6.16.0-1ubuntu2
- ubuntu questing: iproute2 6.16.0-1ubuntu2.1 ยท GPL-2.0-only
- ubuntu questing: iproute2 6.16.0-1ubuntu2.2
- ubuntu resolute: iproute2 6.19.0-1ubuntu1 ยท GPL-2.0-only
- ubuntu resolute: iproute2 6.19.0-1ubuntu1.1 ยท GPL-2.0-only
- ubuntu stonking: iproute2 7.2.0-1ubuntu1 ยท GPL-2.0-only
- ๐ girlified by anthropic/claude-haiku-5.5 on : a language model's rewrite of the original, under its terms