CONNTRACK(8)
CONNTRACK(8) ๐
ok so bestie, we're talking about conntrack from section 8 of the manual โ the netfilter connection tracking era. let's get into it ๐ซถ
โจ NAME โจ
conntrack โ command line interface for netfilter connection tracking ๐
๐ธ SYNOPSIS ๐ธ
conntrack -L [table] [options] [-z]
conntrack -G [table] parameters
conntrack -D [table] parameters
conntrack -I [table] parameters
conntrack -A [table] parameters
conntrack -U [table] parameters
conntrack -E [table] [options]
conntrack -F [table]
conntrack -C [table]
conntrack -S
conntrack -R file
๐ DESCRIPTION ๐
The conntrack utility is literally your full-featured userspace interface to the Netfilter connection tracking system, and it was made to replace the old /proc/net/ip_conntrack interface. rip to that one, she served ๐
This tool can be used to search, list, inspect and maintain the connection tracking subsystem of the Linux kernel. it's giving main character energy in the netfilter world, fr fr.
Using conntrack, you can:
- dump a list of all currently tracked connections โ or a filtered selection of them, if you're feeling picky ๐
- delete connections from the state table
- and even add new ones ๐
In addition, you can also monitor connection tracking events โ like, show an event message (one line, just one) per newly established connection. so every new connection gets its own little spotlight moment โจ
๐ฆ TABLES ๐ฆ
The connection tracking subsystem maintains several internal tables. let's do a vibe check on each one ๐ง
conntrackโ this is the default table. It contains a list of all currently tracked connections through the system. If you don't use connection tracking exemptions (that's theNOTRACKiptables target, iykyk), this means all connections that go through the system. all of them. every single one ๐expectโ this is the table of expectations. Connection tracking expectations are the mechanism used to "expect"RELATEDconnections to existing ones. Expectations are generally used by "connection tracking helpers" (sometimes called application level gateways, aka[ALGs]) for more complex protocols such as FTP, SIP or H.323. it's giving "we knew you were coming" ๐ฎdyingโ this table shows the conntrack entries that have expired and that have been destroyed by the connection tracking system itself, or via theconntrackutility. rip bozo ๐ชฆunconfirmedโ this table shows new entries that are not yet inserted into the conntrack table. These entries are attached to packets that are traversing the stack, but did not reach the confirmation point at thepostroutinghook. they're in their situationship era, not committed yet ๐ญ
okay so real talk: the tablesdyingandunconfirmedare basically only useful for debugging purposes. Under normal operation, it is hard to see entries in any of them. There are corner cases where it is valid to see entries in theunconfirmedtable โ e.g. when packets that are enqueued vianfqueueโ and in thedyingtable, e.g. whenconntrackd(8)runs in event reliable mode. so don't panic if you peek and it's empty, that's the normal vibe ๐ซถ
ok that's part 1 and we are SO not done yet, keep reading bestie ๐
โจ OPTIONS โจ
okay bestie so the options conntrack understands split into a few little cliques, and we're gonna meet all of them ๐
๐ COMMANDS ๐
these tell it what to actually do, and listen โ only one of them can be specified at any given time, okay? pick your fighter, not your whole roster. ๐
-L,--dumpโ list the connection tracking table or the expectation table. the classic "show me everything" move ๐-G,--getโ go search for one particular (matching) entry in the table you picked, and show it off โจ-D,--deleteโ yeet an entry out of the given table ๐๏ธ-I,--createโ make a brand new entry in the given table. if it's already there? it fails. no duplicates allowed, we're not like that ๐ซ-A,--addโ add a new entry to the given table-U,--updateโ update an entry in the given table-E,--eventโ show a real-time event log, like a live feed of everything happening ๐ด-F,--flushโ flush the whole given table. yes, the entire thing ๐ญ-C,--countโ show the table counter ๐ข-S,--statsโ show the in-kernel connection tracking system statistics ๐-R,--load-fileโ load entries from a given file. wanna read from stdin instead? just specify-๐ซถ
๐ธ PARAMETERS ๐ธ
-z,--zeroโ atomically zero the counters after reading them. heads up: this one is only valid when you're using it together with the-L, --dumpcommand options. no solo runs, bestie ๐-o,--output [extended,xml,save,timestamp,id,ktimestamp,labels]โ display output in a certain format. let's break it down:- with the
extendedoutput option, this tool shows you the layer 3 information ๐ - with
ktimestamp, it displays the in-kernel timestamp that's been available since2.6.38(you can turn it on via thesysctl(8)keynet.netfilter.nf_conntrack_timestamp) โฑ๏ธ - the
labelsoutput option tellsconntrackto show the names of connection tracking labels that might be present ๐ท๏ธ - the
userspaceoutput option tells you if the event has been triggered by a process ๐ค
- with the
-e,--event-mask [ALL|NEW|UPDATES|DESTROY][,...]โ set the bitmask of events that are gonna be generated by the in-kernelctnetlinkevent code. with this you can shrink the event messages the kernel spits out down to just the types you're actually interested in. this option can only be used in conjunction with-E, --event๐ซ-b,--buffer-sizevalue โ set the Netlink socket buffer size in bytes. this one's your bestie if the command line tool keeps reportingENOBUFSerrors. if you don't pass this option, the default value sitting at thesysctl(8)keynet.core.rmem_defaultgets used. the tool reports this problem when your process is too slow to handle all the event messages, or like, in other words, when there's enough events to overrun the socket buffer ๐ต. note that a big buffer lowers your chances of hittingENOBUFS, but it also means more memory consumption, so it's giving tradeoff. this option can only be used in conjunction with-E, --event
๐ฆ FILTER PARAMETERS ๐ฆ
-s,--src,--orig-srcIP_ADDRESS โ match only the entries whose source address in the original direction equals whatever you passed as the argument. it implies--mask-srcwhen you use CIDR notation ๐ฏ-d,--dst,--orig-dstIP_ADDRESS โ match only the entries whose destination address in the original direction equals the argument you gave. implies--mask-dstwhen CIDR notation is used ๐ฏ-r,--reply-srcIP_ADDRESS โ match only the entries whose source address in the reply direction equals the argument ๐ฏ-q,--reply-dstIP_ADDRESS โ match only the entries whose destination address in the reply direction equals the argument ๐ฏ-p,--protoPROTO โ specify the layer four (TCP,UDP, ...) protocol ๐ฅ-f,--familyPROTO โ specify the layer three (ipv4,ipv6) protocol. this option is only required together with-L, --dump. if you don't pass it, the default layer 3 protocol isIPv4๐-t,--timeoutTIMEOUT โ specify the timeout โณ-m,--markMARK[/MASK] โ specify the conntrack mark. optionally you can throw in a mask value too. in--updatemode, this mask says which bits should be zeroed before XORing theMARKvalue into thectmark. otherwise, the mask gets logically ANDed with the existing mark before the comparison happens. and in--createmode? the mask is just ignored, periodt ๐-l,--labelLABEL โ specify a conntrack label. this option is only available in conjunction with-L, --dump,-E, --event,-U --updateor-D --delete. it matches the entries whose labels include the ones you passed as arguments. stack up multiple-loptions to specify multiple labels that need to be set ๐ท๏ธ--labelmapPATH โ specify the path to aconnlabel.conffile to load instead of the default one. this option is only available in conjunction with-L, --dump,-E, --event,-U --updateor-D --delete๐--label-addLABEL โ specify the conntrack label to add to the selected conntracks. this option is only available in conjunction with-I, --create,-A, --addor-U, --update. rule of thumb bestie: you gotta use either theconnlabelmatch in your iptables ruleset or thect labelstatement in your nftables ruleset โ that's what turns on ct label support in the kernel, and it's what lets you update labels via-U, --update. otherwise your label updates get straight up ignored ๐--label-del [LABEL]โ specify the conntrack label to delete from the selected conntracks. if no label is given, all labels get deleted ๐ณ. this option is only available in conjunction with-U, --update-c,--secmarkSECMARK โ specify the conntrack selinux security mark ๐-u,--status [ASSURED|SEEN_REPLY|FIXED_TIMEOUT|EXPECTED|OFFLOAD|UNSET][,...]โ specify the conntrack status โจ-n,--src-natโ filter source NAT connections ๐ญ-g,--dst-natโ filter destination NAT connections ๐ญ-j,--any-natโ filter any NAT connections ๐ญ-w,--zoneโ filter by conntrack zone. see the iptablesCTtarget for more information ๐บ๏ธ--orig-zoneโ filter by conntrack zone in the original direction. see the iptablesCTtarget for more information ๐บ๏ธ--reply-zoneโ filter by conntrack zone in the reply direction. see the iptablesCTtarget for more information ๐บ๏ธ--tuple-srcIP_ADDRESS โ specify the tuple source address of an expectation. implies--mask-srcwhen CIDR notation is used ๐ฏ--tuple-dstIP_ADDRESS โ specify the tuple destination address of an expectation. implies--mask-dstwhen CIDR notation is used ๐ฏ--mask-srcIP_ADDRESS โ specify the source address mask. for conntracks, this option is only available in conjunction with-L, --dump,-E, --event,-U --updateor-D --delete. for expectations, this option is only available in conjunction with-I, --create๐ญ--mask-dstIP_ADDRESS โ specify the destination address mask. same limitations as for--mask-src๐ญ
๐ PROTOCOL FILTER PARAMETERS ๐
TCP-specific fields:
--sport,--orig-port-srcPORT โ source port in the original direction--dport,--orig-port-dstPORT โ destination port in the original direction--reply-port-srcPORT โ source port in the reply direction--reply-port-dstPORT โ destination port in the reply direction--statestate โ TCP state, one ofNONE,SYN_SENT,SYN_RECV,ESTABLISHED,FIN_WAIT,CLOSE_WAIT,LAST_ACK,TIME_WAIT,CLOSEorLISTEN๐งต
UDP-specific fields:
--sport,--orig-port-srcPORT โ source port in the original direction--dport,--orig-port-dstPORT โ destination port in the original direction--reply-port-srcPORT โ source port in the reply direction--reply-port-dstPORT โ destination port in the reply direction
ICMP-specific fields:
--icmp-typeTYPE โ ICMP Type. has to be specified numerically ๐ข--icmp-codeCODE โ ICMP Code. has to be specified numerically ๐ข--icmp-idID โ ICMP Id. has to be specified numerically (non-mandatory) ๐ข
UDPlite-specific fields:
--sport,--orig-port-srcPORT โ source port in the original direction--dport,--orig-port-dstPORT โ destination port in the original direction--reply-port-srcPORT โ source port in the reply direction--reply-port-dstPORT โ destination port in the reply direction
SCTP-specific fields:
--sport,--orig-port-srcPORT โ source port in the original direction--dport,--orig-port-dstPORT โ destination port in the original direction--reply-port-srcPORT โ source port in the reply direction--reply-port-dstPORT โ destination port in the reply direction--statestate โ SCTP state, one ofNONE,CLOSED,COOKIE_WAIT,COOKIE_ECHOED,ESTABLISHED,SHUTDOWN_SENT,SHUTDOWN_RECD,SHUTDOWN_ACK_SENT๐งต--orig-vtagvalue โ Verification tag (32-bits value) in the original direction ๐--reply-vtagvalue โ Verification tag (32-bits value) in the reply direction ๐
DCCP-specific fields (needs Linux >= 2.6.30):
--sport,--orig-port-srcPORT โ source port in the original direction--dport,--orig-port-dstPORT โ destination port in the original direction--reply-port-srcPORT โ source port in the reply direction--reply-port-dstPORT โ destination port in the reply direction--statestate โ DCCP state, one ofNONE,REQUEST,RESPOND,PARTOPEN,OPEN,CLOSEREQ,CLOSING,TIMEWAIT๐งต--role [client|server]โ role that the original conntrack tuple is tracking ๐ญ
GRE-specific fields:
--srckey,--orig-key-srcKEY โ source key in the original direction (in hexadecimal or decimal) ๐--dstkey,--orig-key-dstKEY โ destination key in the original direction (in hexadecimal or decimal) ๐--reply-key-srcKEY โ source key in the reply direction (in hexadecimal or decimal) ๐--reply-key-dstKEY โ destination key in the reply direction (in hexadecimal or decimal) ๐
๐ DIAGNOSTICS ๐
the exit code is 0 for correct function, bestie โจ errors that look like they were caused by invalid command line parameters get you an exit code of 2 ๐ซ and any other errors? those hand you an exit code of 1 ๐
๐ EXAMPLES ๐
okay bestie this is the part where it all comes together, the little recipes, the greatest hits, the "just copy-paste it and it works" section ๐ซถ every single one of these is literally verbatim, don't you dare change a character:
conntrack -Lโ dumps the connection tracking table in/proc/net/ip_conntrackformat. the classic. the OG. the one you run when you have zero thoughts in your head and just want to see things ๐conntrack -L -o extendedโ shows the connection tracking table in/proc/net/nf_conntrackformat, but with extra info on top. it's giving "deluxe edition" โจconntrack -L -o xmlโ shows the connection tracking table in XML. for when you want your flows to look like a very serious document ๐conntrack -L -o saveโ shows the connection tracking table in conntrack syntax format, i.e. the format that can be fed right back in. it's giving "round trip" ๐conntrack -L -f ipv6 -o extendedโ only dumps IPv6 connections, in/proc/net/nf_conntrackformat, with the additional information. v6 girlies rise up ๐conntrack -L --src-natโ shows the source NAT connections. just the NAT ones. filtered. curated. ๐conntrack -E -o timestampโ shows connection events together with the timestamp. live updates and receipts ๐conntrack -D -s 1.2.3.4โ deletes all flows whose source address is1.2.3.4. poof. gone. no cap ๐conntrack -U -s 1.2.3.4 -m 1โ sets connmark to1on all the flows whose source address is1.2.3.4. marking them. claiming them. branding them fr fr ๐ฅ
and here's the fancy one, so let me give it the whole block because it spans two lines and you know I'm not about to mess that up:
conntrack -L -w 11 -o save | sed s/-w 11/-w 12/g | conntrack --load-file
-
conntrack -L -w 11 -o save | sed s/-w 11/-w 12/g | conntrack --load-file -โ copies all entries from ct zone11to ct zone12. yes it's a whole pipeline. yes it's lowkey iconic. theseddoes the little zone switcheroo and--load-file -reads it right back off stdin ๐ฆ
๐ BUGS ๐
found something cursed? don't just sit there screaming into the void bestie, please, report them to netfilter-devel@vger.kernel.org or file a bug in Netfilter's bugzilla at https://bugzilla.netfilter.org. they want to know. we all want to know ๐
๐ SEE ALSO ๐
go read these next, they're the friends of the family:
also, see http://conntrack-tools.netfilter.org for the whole vibe ๐
๐ AUTHORS ๐
the lore, preserved exactly:
Jay Schulist, Patrick McHardy, Harald Welte and Pablo Neira Ayuso wrote the kernel-level "ctnetlink" interface that is used by the conntrack tool.
Pablo Neira Ayuso wrote and maintains the conntrack tool, and Harald Welte added support for conntrack-based accounting counters.
The man page was written by Harald Welte <laforge@netfilter.org> and Pablo Neira Ayuso <pablo@netfilter.org>.
and that's the whole page, bestie!! this little masterpiece is part of the conntrack-tools package, dated Aug 9, 2019, and it lives in section 8 of the manual, aka CONNTRACK(8) ๐ thanks for reading all three parts, you ate that fr fr, now go track some connections ๐โจ๐ฆ
๐ฆ where this page comes from
- alpine 3.24: conntrack-tools-doc 1.4.9-r0 ยท GPL-2.0-or-later
- arch rolling: conntrack-tools 1.4.9-1 ยท GPL-2.0-or-later
- fedora 43: conntrack-tools 1.4.9-2.fc43 ยท GPL-2.0-only
- nixpkgs unstable: conntrack-tools 1.4.9
- ubuntu resolute: conntrack 1:1.4.9-1 ยท GPL-2.0-or-later
- ubuntu stonking: conntrack 1:1.4.9-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