20_check_host_ports_firewall.yml - Usage Guide
Purpose
On each host:
- Which ports are listening (
ss -tulnp) - How they are open — all interfaces / localhost only / a specific IP
- Which application is listening (process name + pid)
- Firewall — UFW, firewalld (if present),
iptables+nftsummary; rules that mention listening ports
Read-only; does not add or delete rules. Each host reports the state on its own disk / own kernel (HOST header).
Script: playbooks/files/host_ports_firewall_check.py
What does “how is it open?” mean?
| BIND | Meaning |
|---|---|
ALL_INTERFACES | 0.0.0.0 / :: — external access may be possible (if the firewall allows it) |
LOCALHOST_ONLY | Only local processes can reach it |
PRIVATE_IP / SPECIFIC_IP | Listening on a specific interface IP |
Listening ≠ the firewall opening it to the outside. Check INPUT policy / UFW / nft rules in the firewall section of the report.
Difference from 02
| Playbook | Scope |
|---|---|
| 02 | Kubernetes NodePort services |
| 20 | Host OS listening sockets + iptables/nft/UFW |
Requirements
hosts: allbecome: true(for process names + iptables/nft)python3,ss(iproute2)
How to run
ansible-playbook -i inventories/cagatayuresincom/hosts.ini playbooks/20_check_host_ports_firewall.yml
ansible-playbook -i inventories/musteri_a/hosts.ini playbooks/20_check_host_ports_firewall.yml --limit workers
How to read the output
- Listening ports table → port + bind + application
- UFW / firewalld (if installed)
- iptables/nft → policy,
dpt:/dportlines for listening ports, NAT summary - Risk summary → services listening on all interfaces
On a K8s node, kube-proxy/CNI rules can be very long; the report filters and shortens relevant lines.
Notes
- A process field of
-means missing permission/root (the playbook usesbecome). - Ports inside containers may show as
*:or a CNI IP on the host; the application name may becontainerd/docker-proxy.