Skip to content

Conversation

@TotallyMonica
Copy link

@TotallyMonica TotallyMonica commented Dec 14, 2025

Summary

This PR creates a script that parses iptables and ip6tables rules, collecting the following metrics per rule:

  • Table
  • Chain
  • Rule's line number
  • Action (Labeled in iptables -L and ip6tables -L as target)
  • Protocol
  • Incoming interface
  • Outgoing interface
  • Source address
  • Destination address
  • Extra information
  • Rule hit statistics
    • Byte count (as iptables_bytes_total and ip6tables_bytes_total)
    • Packet count (as iptables_packets_total and ip6tables_bytes_total)

References

PR is largely based on prometheus/node_exporter#1264, implementing the feedback received by it. As such, no files are being written to or read from.

Notes

Due to how iptables is designed, iptables must be ran as uid 0, so this means one of the following:

  • /sbin/iptables must be setuid
  • iptables.py must be ran as root
  • /sbin/iptables must have the capabilities CAP_NET_ADMIN+ep

Testing done

  • Hosts
    • Ubuntu 24.04.3 Server with iptables v1.8.10
    • Debian 13.2 with iptables v1.8.11

Based off of https://github.com/FelixDefrance/node_exporter commit 0e48c29, used in PR prometheus/node_exporter#1264

Signed-off-by: Monica Hanson <mhanson@monicarose.tech>
Signed-off-by: Monica Hanson <mhanson@monicarose.tech>
Signed-off-by: Monica Hanson <mhanson@monicarose.tech>
Signed-off-by: Monica Hanson <mhanson@monicarose.tech>
Signed-off-by: Monica Hanson <mhanson@monicarose.tech>
Signed-off-by: Monica Hanson <mhanson@monicarose.tech>
Signed-off-by: Monica Hanson <mhanson@monicarose.tech>
@TotallyMonica TotallyMonica marked this pull request as ready for review December 14, 2025 17:53
Signed-off-by: Monica Hanson <mhanson@monicarose.tech>
Should help with web server compatibility

Signed-off-by: Monica Hanson <mhanson@monicarose.tech>
Signed-off-by: Monica Hanson <mhanson@monicarose.tech>
Signed-off-by: Monica Hanson <mhanson@monicarose.tech>
Signed-off-by: Monica Hanson <mhanson@monicarose.tech>
Signed-off-by: Monica Hanson <mhanson@monicarose.tech>
Signed-off-by: Monica Hanson <mhanson@monicarose.tech>
Signed-off-by: Monica Hanson <mhanson@monicarose.tech>
Signed-off-by: Monica Hanson <mhanson@monicarose.tech>
By extent, this fixes an F841 violation

Signed-off-by: Monica Hanson <mhanson@monicarose.tech>
Signed-off-by: Monica Hanson <mhanson@monicarose.tech>
Signed-off-by: Monica Hanson <mhanson@monicarose.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant