XTABLES-MONITOR(8)

๐ŸŒธ NAME ๐ŸŒธ

okay so bestie, this is xtables-monitor โ€” show changes to rule set and trace-events. it's the xtables-monitor(8) page from the iptables 1.8.13 squad, and we're about to make it make sense. ๐Ÿ’…


โœจ SYNOPSIS โœจ

xtables-monitor [-t] [-e] [-4||-6]

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so xtables-monitor is your little live wire for two things: monitoring changes to the ruleset, or showing rule evaluation events for packets that have been tagged using the TRACE target. it will literally run until the user aborts execution โ€” typically by using CTRL-C (Ctrl+C). no cap, it just keeps going until you stop it. ๐Ÿ›‘


๐ŸŽ€ OPTIONS ๐ŸŽ€

  • -e, --event โ€” watch for updates to the rule set. updates include creation of new tables, chains and rules, plus the name of the program that caused the rule update. ๐Ÿ‘€
  • -t, --trace โ€” watch for trace events generated by packets that have been tagged using the TRACE target. ๐Ÿ•ต๏ธโ€โ™€๏ธ
  • -4 โ€” restrict output to IPv4. 4๏ธโƒฃ
  • -6 โ€” restrict output to IPv6. 6๏ธโƒฃ

๐ŸŒˆ EXAMPLE OUTPUT ๐ŸŒˆ

๐Ÿฆ‹ xtables-monitor --trace ๐Ÿฆ‹

xtables-monitor --trace

        1 TRACE: 2 fc475095 raw:PREROUTING:rule:0x3:CONTINUE -4 -t raw
       -A PREROUTING -p icmp -j TRACE
        2 PACKET: 0 fc475095 IN=lo LL=0x304 0000000000000000000000000800
       SRC=127.0.0.1 DST=127.0.0.1 LEN=84 TOS=0x0 TTL=64 ID=38349DF
        3 TRACE: 2 fc475095 raw:PREROUTING:return:
        4 TRACE: 2 fc475095 raw:PREROUTING:policy:ACCEPT
        5 TRACE: 2 fc475095 filter:INPUT:return:
        6 TRACE: 2 fc475095 filter:INPUT:policy:DROP
        7 TRACE: 2 0df9d3d8 raw:PREROUTING:rule:0x3:CONTINUE -4 -t raw
       -A PREROUTING -p icmp -j TRACE

the first line shows a packet entering rule set evaluation. the protocol number is shown (AF_INET in this case), then a packet identifier number that lets you correlate messages coming from rule set evaluation of this packet. after that, the rule that was matched by the packet is shown โ€” this is the TRACE rule that turns on tracing events for this packet. ๐Ÿ”

the second line dumps information about the packet. incoming interface and packet headers such as source and destination addresses are shown. ๐Ÿ“ฆ

the third line shows that the packet completed traversal of the raw table PREROUTING chain, and is returning, followed by use of the chain policy to make accept/drop decision (the example shows accept being applied). the fifth line shows that the packet leaves the filter INPUT chain, i.e., no rules in the filter table's INPUT chain matched the packet. it then got DROPPED by the policy of the INPUT table, as shown by line six. the last line shows another packet arriving โ€” the packet id is different. ๐Ÿ’€

when using the TRACE target, it is usually a good idea to only select packets that are relevant, for example via:

iptables -t raw -A PREROUTING -p tcp --dport 80 --syn -m limit --limit 1/s -j TRACE

๐Ÿ’œ xtables-monitor --event ๐Ÿ’œ

xtables-monitor --event
         1 EVENT: nft: NEW table: table filter ip flags 0 use 4 handle
       444
         2 EVENT: # nft: ip filter INPUT use 2 type filter hook input
       prio 0 policy drop packets 0 bytes 0
         3 EVENT: # nft: ip filter FORWARD use 0 type filter hook
       forward prio 0 policy accept packets 0 bytes 0
         4 EVENT: # nft: ip filter OUTPUT use 0 type filter hook output
       prio 0 policy accept packets 0 bytes 0
         5 EVENT: -4 -t filter -N TCP
         6 EVENT: -4 -t filter -A TCP -s 192.168.0.0/16 -p tcp -m tcp
       --dport 22 -j ACCEPT
         7 EVENT: -4 -t filter -A TCP -p tcp -m multiport --dports
       80,443 -j ACCEPT
         8 EVENT: -4 -t filter -A INPUT -p tcp -j TCP
         9 EVENT: -4 -t filter -A INPUT -m conntrack --ctstate
       RELATED,ESTABLISHED -j ACCEPT
        10 NEWGEN: GENID=13904 PID=25167 NAME=iptables-nftables-restore

this example shows event monitoring. line one shows creation of a table (filter in this case), followed by three base hooks INPUT, FORWARD and OUTPUT. the iptables-nftables tools all create tables and base chains automatically when needed, so this is expected when a table was not yet initialized or when it is re-created from scratch by iptables-nftables-restore. line five shows a new user-defined chain (TCP) being added, followed by adding a few rules. the last line shows that a new ruleset generation has become active, i.e., the rule set changes are now active. this also lists the process id and the program name. ๐Ÿ”ฅ


๐Ÿšซ LIMITATIONS ๐Ÿšซ

okay so here's the catch: xtables-monitor only works with rules added using iptables-nftables. rules added using iptables-legacy cannot be monitored. periodt. ๐Ÿ’…


๐Ÿ˜ญ BUGS ๐Ÿ˜ญ

if something's busted, it should be reported by sending email to netfilter-devel@vger.kernel.org or by filing a report on https://bugzilla.netfilter.org/. ๐Ÿซถ


๐Ÿ“š SEE ALSO ๐Ÿ“š

iptables(8), xtables(8), nft(8) โ€” go read those too, bestie. ๐Ÿ‘‘


and that's the whole page, bestie! this one's from iptables 1.8.13, and the manual is XTABLES-MONITOR(8). stay hydrated, check your ruleset, and slay ๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from