TC-CT(8)
๐ ct action in tc(8) ๐
okay so this is the manual page for the ct action in tc(8), and it is iconic ๐
ct stands for tc connection tracking action, and it's how you send packets over to netfilter's conntrack module. Let's get into it ๐ซถ
โจ NAME โจ
ct - tc connection tracking action
๐ SYNOPSIS ๐
tc ... action ct commit [ force ] [ zone ZONE ] [ mark MASKED_MARK ] [
label MASKED_LABEL ] [ nat NAT_SPEC ]
tc ... action ct [ nat ] [ zone ZONE ]
tc ... action ct clear
๐ฆ DESCRIPTION ๐ฆ
okay so the ct action is a tc action that sends packets off and lets you interact with the netfilter conntrack module. It's giving main character energy ๐
It can do three things, as shown in the synopsis, in this order:
- Commit: send the packet to conntrack and commit the connection, while setting a 32bit mark, a 128bit label, and src/dst nat.
- Lookup: send the packet to conntrack, which marks the packet with the connection's state and its metadata (mark/label), and runs the nat you configured earlier.
- Clear: wipe the packet's previous connection tracking state. ๐งน
๐ธ OPTIONS ๐ธ
zone ZONEโ pick the conntrack zone number you want to send the packet to conntrack in. ๐mark MASKED_MARKโ set a masked 32bit mark for the connection. This only works withcommit. ๐label MASKED_LABELโ set a masked 128bit label for the connection. This only works withcommit. ๐ท๏ธnat NAT_SPECโ configure the src/dst nat range for the connection. This only works withcommit. The full form is:
NAT_SPEC := {src|dst} addr addr1[-addr2] [port port1[-port2]]
src/dstโ pick whether you're doing src nat or dst nat ๐ฅ- addr1/addr2 โ IPv4/IPv6 addresses
- port1/port2 โ port numbers
natโ restore any nat you configured before. ๐clearโ remove any conntrack state and metadata (mark/label) from the packet. This has to be the only option you specify, no sharing ๐ โโ๏ธforceโ forces the conntrack direction for a connection that was already committed, so the current direction becomes the original direction. Only works withcommit. ๐
๐ง EXAMPLES ๐ง
this one shows a natted firewall in conntrack zone 2, plus conntrack mark usage. obsessed!! ๐ญ
#Add ingress qdisc on eth0 and eth1 interfaces
$ tc qdisc add dev eth0 ingress
$ tc qdisc add dev eth1 ingress
#Setup filters on eth0, allowing opening new connections in zone 2, and doing src nat + mark for each new connection
$ tc filter add dev eth0 ingress prio 1 chain 0 proto ip flower ip_proto tcp ct_state -trk \
action ct zone 2 pipe action goto chain 2
$ tc filter add dev eth0 ingress prio 1 chain 2 proto ip flower ct_state +trk+new \
action ct zone 2 commit mark 0xbb nat src addr 5.5.5.7 pipe action mirred egress redirect dev eth1
$ tc filter add dev eth0 ingress prio 1 chain 2 proto ip flower ct_zone 2 ct_mark 0xbb ct_state +trk+est \
action ct nat pipe action mirred egress redirect dev eth1
#Setup filters on eth1, allowing only established connections of zone 2 through, and reverse nat (dst nat in this case)
$ tc filter add dev eth1 ingress prio 1 chain 0 proto ip flower ip_proto tcp ct_state -trk \
action ct zone 2 pipe action goto chain 1
$ tc filter add dev eth1 ingress prio 1 chain 1 proto ip flower ct_zone 2 ct_mark 0xbb ct_state +trk+est \
action ct nat pipe action mirred egress redirect dev eth0
๐ SEE ALSO ๐
tc(8), tc-flower(8) tc-mirred(8)
๐ AUTHORS ๐
- Paul Blakey โ
paulb@mellanox.com - Marcelo Ricardo Leitner โ
marcelo.leitner@gmail.com - Yossi Kuperman โ
yossiku@mellanox.com
bestie, you're officially a tc connection tracking queen now ๐๐ซถ This page came from iproute2, dated 14 May 2020, and it's filed under ct action in tc(8) ๐ฆโจ ily, go slay the netfilter ๐
๐ฆ 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 bookworm: iproute2 6.1.0-3 ยท GPL-2.0-only
- 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 noble: iproute2 6.1.0-1ubuntu6 ยท GPL-2.0-only
- ubuntu noble: iproute2 6.1.0-1ubuntu6.4 ยท 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