Pcornel
Linux

Linux Firewall

Cheat sheet · https://pcornel.dk/topic.php?topic=2809

Back to the Topic

Answer

A Linux host firewall filters packets in the kernel's netfilter framework. Rules are written with nftables (modern), iptables (legacy, often a front end to nftables) or managed by firewalld (RHEL) or UFW (Ubuntu).

Remember

Use one management tool per host — mixing firewalld, UFW and hand-written rules leads to surprises. Find out which one is active, then read the full ruleset. Allow your SSH session before enabling a default-deny policy.

First checks

  • nft list ruleset — all nftables rules
  • iptables -S; iptables -t nat -S — iptables rules (if used)
  • firewall-cmd --list-all — firewalld zone settings
  • ufw status verbose — UFW rules and defaults
  • ss -tulpn — which services listen

Commands

sudo nft list ruleset
Full nftables ruleset.
nft
nft list ruleset
systemctl is-active firewalld ufw nftables
iptables -V
ss -tlnp
ip nat
ip filter

Verify in this order

packet arrives → netfilter hooks → rules in order → accept/drop → service receives it

Where it usually breaks

First mismatch in link/interface → address/namespace → route/neighbor → firewall/policy → socket/daemon → DNS/TLS/SSH/application peer path; preserve identity/native diagnostic/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2809

Confirmation

Confirm action

Continue?