conntrack: command line interface for netfilter connection tracking
conntrack -L [table] [options] [-z]
conntrack -G [table] parameters
conntrack -D [table] parameters
conntrack -E [table] [options]
conntrack -F [table]
conntrack -C [table]
conntrack -S
Options you will use
-L, --dump- List connection tracking or expectation table.
-G, --get- Search for and show a particular (matching) entry in the given table.
-D, --delete- Delete an entry from the given table (every entry the filters match).
-E, --event- Display a real-time event log.
-F, --flush- Flush the whole given table.
-C, --count- Show the table counter.
-S, --stats- Show the in-kernel connection tracking system statistics.
-o, --output FORMAT- Display output in a certain format, e.g. extended (with the layer 3 information), xml, timestamp, id.
-s, --src, --orig-src IP_ADDRESS- Match only entries whose source address in the original direction equals the one specified as argument.
-d, --dst, --orig-dst IP_ADDRESS- Match only entries whose destination address in the original direction equals the one specified as argument.
-r, --reply-src IP_ADDRESS- Match only entries whose source address in the reply direction equals the one specified as argument.
-q, --reply-dst IP_ADDRESS- Match only entries whose destination address in the reply direction equals the one specified as argument.
-p, --proto PROTO- Specify layer four (TCP, UDP, ...) protocol. Needed before the protocol options below.
--sport, --orig-port-src PORT- Source port in original direction.
--dport, --orig-port-dst PORT- Destination port in original direction.
--state STATE- TCP state, one of NONE, SYN_SENT, SYN_RECV, ESTABLISHED, FIN_WAIT, CLOSE_WAIT, LAST_ACK, TIME_WAIT, CLOSE or LISTEN.
Examples
$ sudo conntrack -L -p tcp --dport 443the tracked TCP flows to port 443
$ sudo conntrack -L -d 203.0.113.10flows to one address
$ sudo conntrack -D -d 203.0.113.10delete them: the next packet is a new flow
$ sudo conntrack -Chow many entries the table holds
Gotchas
- Needs root (CAP_NET_ADMIN). The summary line ("N flow entries have been shown." / "... deleted.") goes to stderr; -D exits 1 when nothing matched.
- Firewalls and NetworkPolicy implementations decide on a flow's first packet and let the rest of an established flow through: a connection open before a deny rule keeps working until its conntrack entry is deleted (conntrack -D) and the next packet has to pass the rules again.
Try conntrack in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.