Reference notes.

Firewalls filter network traffic based on rules, controlling what enters and exits a network or host. They operate primarily at Layer 3 (IP) and Layer 4 (TCP/UDP).

Types of Firewalls

TypeDescriptionExample
Packet filterStateless, examines individual packetsBasic ACLs
StatefulTracks connection statenftables, iptables, pf
Application (L7)Inspects application dataWAF, next-gen firewalls
Host-basedRuns on individual hostsnftables, iptables, Windows Firewall
Network-basedDedicated appliance/devicepfSense, OPNsense, Cisco Secure Firewall

Stateful vs Stateless

  • Stateless: Each packet evaluated independently. Must explicitly allow both directions.
  • Stateful: Tracks connections. Return traffic automatically allowed for established connections.

Linux Firewalls

  • nftables - The standard Linux firewall framework, replacing iptables. Cleaner syntax, better performance, unified IPv4/IPv6 handling. Default on Debian 10+, RHEL 8+, and most modern distributions.
  • iptables - Legacy firewall, still widely documented. Modern distributions provide iptables as a compatibility wrapper (iptables-nft) that translates rules to nftables under the hood.
  • UFW - Simplified frontend (Ubuntu/Debian) that drives iptables commands (backed by iptables-nft on modern Debian/Ubuntu)
  • firewalld - Zone-based frontend, uses nftables backend by default (RHEL/Fedora)

Netfilter Hooks

Both nftables and legacy iptables attach chains to five Linux Netfilter hooks along the packet path:

  • prerouting - Packets entering the host before a routing decision is made (e.g., DNAT)
  • input - Incoming traffic destined for the host
  • forward - Traffic passing through the host (routing)
  • output - Outgoing traffic originating from the host
  • postrouting - Packets leaving the host after routing (e.g., SNAT / masquerade)

Unlike iptables, nftables defines no default tables or chains — you create your own tables (commonly inet for unified IPv4/IPv6) and attach base chains explicitly to the hooks you need.

macOS/BSD: pf (Packet Filter)

OpenBSD’s packet filter, also used on macOS and FreeBSD.

Common Firewall Rules Pattern

  1. Default deny incoming
  2. Allow all outgoing
  3. Allow established/related incoming (stateful)
  4. Allow loopback
  5. Allow essential ICMP / ICMPv6 — never blindly block ICMP, as doing so breaks IPv4 Path MTU Discovery (PMTUD) and completely breaks IPv6 Neighbour Discovery (NDP) and SLAAC (RFC 4890)
  6. Allow specific services (SSH, HTTP, etc.)
  7. Log dropped packets

Security Best Practices

  • Default deny - Block everything, allow only what’s needed
  • Principle of least privilege - Minimal necessary access
  • Limit SSH access - Restrict by IP or use fail2ban
  • Rate limiting - Prevent brute force and DDoS
  • Log and monitor - Track blocked traffic
  • Keep rules simple - Complex rules lead to mistakes
  • Regular audits - Review and clean up rules

eBPF and XDP

eBPF (extended Berkeley Packet Filter) enables programmable packet processing in the Linux kernel without modifying kernel code. XDP (eXpress Data Path) uses eBPF to process packets at the earliest possible point in the network stack, achieving near-hardware speeds.

  • Cilium - eBPF-based networking, security, and observability for Kubernetes. Replaces kube-proxy (which supports nftables mode GA since Kubernetes 1.33, alongside legacy iptables) with eBPF programs.
  • XDP firewalling - Process and filter packets before they reach the normal network stack, enabling high-performance DDoS mitigation.
  • Cloudflare, Meta, and others use eBPF/XDP heavily for DDoS protection and load balancing at scale.

Cloud-Native Firewalls

  • Security groups - AWS, Azure, GCP all provide stateful virtual firewalls attached to instances/VMs
  • Network policies - Kubernetes-native L3/L4 rules (enforced by CNI plugins like Cilium or Calico)
  • Service meshes - mTLS and L7 policy enforcement (Istio, Linkerd)
  • WAF-as-a-service - Cloudflare, AWS WAF, etc. for L7 filtering

See Also

References