Letting monitoring through a strict firewall
A firewall that blocks your own monitoring makes every outage look like a mystery. A few precise rules keep checks working and everything else closed.
Why do probes fail after I add a firewall?
Usually because ping, the check port or the source addresses of the monitor were not allowed. A default-deny rule set drops anything you did not list, and monitoring often uses ICMP echo, a dedicated health URL or an exporter on a high port. The fix is not to loosen the firewall, but to name the probes it should accept.
Should I allow ping?
Yes, with a rate limit. Blocking ICMP echo hides the server from many uptime tools and makes network fault-finding harder, while answering pings costs nothing measurable. A limit of a few replies per second per source stops ping floods from wasting the port. For IPv6, allow ICMPv6 broadly, because neighbour discovery and path MTU messages depend on it.
nft add rule inet hostfw input icmp type echo-request limit rate 4/second burst 8 packets accept
nft add rule inet hostfw input icmpv6 type { echo-request, nd-neighbor-solicit, nd-router-advert, packet-too-big } accept
How do I allow an outside uptime checker?
Check whether its probes need anything beyond your public service. A monitor that fetches https://example.com/health uses the same port 443 as your visitors, so no extra rule is needed. A monitor that checks SSH, a database port or a custom TCP service needs that port opened to its addresses only. Most commercial checkers publish their probe address lists; keep them in a named set so updates are one command.
nft add set inet hostfw probes '{ type ipv4_addr; flags interval; }'
nft add element inet hostfw probes '{ 198.51.100.0/27, 203.0.113.128/26 }'
nft add rule inet hostfw input ip saddr @probes tcp dport { 22, 5432 } accept
Refresh the set from the provider's list on a schedule, for example a daily script that downloads the list and replaces the elements, so a probe added on their side does not show up as a false alarm on yours.
How do I expose metrics without exposing them to everyone?
Bind exporters to a private address or localhost, and let your collector reach them through a tunnel or an allow rule. Prometheus node_exporter listens on 9100 on every interface by default, which publishes detailed information about your machine. Restrict it with a listen address, or put a reverse proxy with TLS and basic authentication in front.
# /etc/default/prometheus-node-exporter (Debian and Ubuntu) ARGS="--web.listen-address=10.20.0.1:9100"
With no private network between servers, the cleanest layout is a WireGuard link from each server to the monitoring host, with exporters listening on the tunnel addresses. The Company VPN gateways page sketches that design.
| Check type | Port | Rule needed |
|---|---|---|
| HTTP or HTTPS health URL | 80, 443 | None beyond your public web rule |
| Ping | ICMP echo | Rate-limited accept |
| TCP port check (SSH, database) | Service port | Accept from the probe set only |
| Metrics scrape | 9100 and similar | Accept on the tunnel interface only |
What should a good health endpoint do?
Exercise the parts that break, quickly and without side effects. Return 200 when the application can reach its database and cache and has free disk space; return 503 otherwise. Keep it fast, under 100 ms, and cheap enough to call every 30 seconds from several locations. Exclude it from access logs or sample it, so it does not bury real traffic.
How do I test from the outside?
Run the same checks from another machine you control, not from the server itself. Local tests pass through the loopback interface and skip the firewall entirely, which hides the mistake you are trying to catch.
ping -c 3 192.0.2.40
nc -vz -w 3 192.0.2.40 5432
curl -s -o /dev/null -w '%{http_code} %{time_total}\n' https://example.com/health
Which events deserve an alert?
Few, and actionable ones. Alert on the service being unreachable from two or more probe locations, on disk space crossing a threshold such as 85 percent, on a degraded RAID array and on certificates close to expiry. Graph the rest. An alert that fires daily for something nobody fixes trains everyone to ignore the one that matters.
# a degraded mirror check for any monitoring agent grep -q '\[.*_.*\]' /proc/mdstat && echo CRITICAL || echo OK
Can I monitor traffic on the port?
Yes, from the server. Tools such as vnstat keep daily and monthly totals with almost no overhead, which is useful on Singapore, Sydney and Mumbai machines where the plan includes a monthly traffic allowance. In Europe and Canada the port is unmetered, so the totals are for capacity planning rather than billing. The Unmetered bandwidth explained article explains the difference.
Related pages
Build an iptables firewall
A default-deny host firewall with iptables or nftables: allow SSH and web, rate-limit new connections, cover IPv6 and keep the rules across reboots.
Read moreCompany VPN gateways
Small, efficient machines for WireGuard and IPsec gateways that connect staff, offices and servers privately.
Read moreUnmetered bandwidth explained
What unmetered means, how much a 1 Gbps port can move in a month and how traffic allowances work in Asia-Pacific.
Read moreRecognise a network attack
Tell an attack from a traffic spike using the server's own counters, know what the upstream filtering handles, and what to send in a ticket.
Read moreQuestions and answers
Should a server answer ping?
Yes, with a rate limit. It helps monitoring and fault-finding and costs almost nothing. Always allow the ICMPv6 types IPv6 needs.
How do I let an uptime service through without opening the port to all?
Put the probe addresses in a named firewall set and accept the check port from that set only. Refresh the set from the provider list regularly.
Is node_exporter safe to leave on port 9100?
Not on a public address. Bind it to localhost or a tunnel address and let the collector reach it over WireGuard.
Why does my local test pass while outside probes fail?
Local traffic uses the loopback interface and bypasses most firewall rules. Always test from another machine.
Do you monitor my services for me?
Monitoring inside the server is yours to set up, with full root access and any tools you like. Hardware faults you report are fixed by the data centre team.