Prometheus exporter for iptables and ip6tables rule counts.
It provides insights into how many rules are active in each chain and table, helping you monitor firewall configurations and detect unexpected changes or massive rule additions.
- Scrapes both IPv4 (
iptables) and IPv6 (ip6tables). - Collects metrics from multiple tables (filter, nat, mangle, etc.).
- Reports rule counts per chain and total counts per table.
- Includes scrape success and duration metrics.
- Built-in Go and process metrics.
| Metric Name | Type | Labels | Description |
|---|---|---|---|
iptables_rules |
Gauge | family, table, chain |
Number of iptables rules in a specific chain. |
iptables_rules_action |
Gauge | family, table, chain, action |
Number of rules by action (target) in a specific chain. |
iptables_rules_table |
Gauge | family, table |
Total number of iptables rules in a table. |
iptables_scrape_success |
Gauge | family |
1 if the last scrape was successful, 0 otherwise. |
iptables_scrape_duration_seconds |
Gauge | family |
Duration of the last scrape in seconds. |
- Permissions: The exporter must run as
root(or withCAP_NET_ADMIN/CAP_NET_RAWcapabilities) to executeiptables-save. - System: Linux with
iptables-saveand/orip6tables-savebinaries installed in the PATH. - Build: Go 1.23+ (if building from source).
- License: MIT.
Use the provided Makefile:
make buildThe binary will be placed in ./bin/iptables_exporter.
If you don't have Go installed locally, the Makefile will attempt to build using Docker automatically.
CGO_ENABLED=0 go build -trimpath -ldflags="-s -w" -o iptables_exporter .You can install the exporter using the provided Makefile:
- Build and install the binary:
sudo make install
- Install the systemd service:
sudo make install-service
- Reload systemd and start the service:
sudo systemctl daemon-reload sudo systemctl enable --now iptables_exporter
To uninstall:
sudo make uninstall
sudo systemctl daemon-reload- Build the binary.
- Copy the binary to
/usr/local/bin/:sudo cp bin/iptables_exporter /usr/local/bin/
- Copy the unit file to
/etc/systemd/system/:sudo cp iptables_exporter.service /etc/systemd/system/
- Reload systemd and start the service:
sudo systemctl daemon-reload sudo systemctl enable --now iptables_exporter - Check status:
sudo systemctl status iptables_exporter
sudo ./bin/iptables_exporter [flags]The exporter can be configured via command-line flags or environment variables. Flags take precedence over environment variables.
| Flag | Environment Variable | Default | Description |
|---|---|---|---|
-listen |
LISTEN_ADDRESS |
:9105 |
Address to listen on for web interface and telemetry. |
-metrics-path |
METRICS_PATH |
/metrics |
Path under which to expose metrics. |
-ipv6 |
ENABLE_IPV6 |
true |
Collect ip6tables metrics too. |
-tables |
TABLES |
filter,nat,mangle,raw,security |
Comma-separated list of tables to scrape. |
-timeout |
TIMEOUT |
2s |
Timeout per iptables command execution. |
Running the exporter with custom tables:
sudo ./iptables_exporter -tables "filter,nat" -listen ":9105"Then check the metrics:
curl http://localhost:9105/metricsA simple health check is available at /healthz.