Kahibaro
Discord Login Register

Firewalls in depth

Understanding Linux Firewall Architecture

Linux offers multiple layers where firewalling can occur. For advanced administration you need to understand how these pieces fit together:

In depth firewall work usually means:

Netfilter Packet Flow in Detail

The kernel checks packets at several hook points. For IPv4, the classic iptables chains correspond to these hooks:

Conceptually, a packet from outside to a local service flows like:

  1. NIC receives packet
  2. raw table PREROUTING (optional)
  3. mangle table PREROUTING
  4. nat table PREROUTING
  5. Routing decision: is this packet for us or to be forwarded?
  6. If for us:
    • mangle table INPUT
    • filter table INPUT
    • Delivered to local socket
  7. If forwarded:
    • mangle table FORWARD
    • filter table FORWARD
    • mangle table POSTROUTING
    • nat table POSTROUTING
    • Outgoing NIC

For outgoing packets generated by the host:

  1. Local process creates packet
  2. raw table OUTPUT
  3. mangle table OUTPUT
  4. nat table OUTPUT
  5. Routing decision
  6. mangle table POSTROUTING
  7. nat table POSTROUTING
  8. Outgoing NIC

Understanding this flow is crucial for advanced tasks like:

Tables, Chains, and Targets

Netfilter is organized into tables. Each table has chains (hooks), and each chain has rules with matches and targets.

Common tables (iptables/nftables concepts apply, though syntax differs):

Common targets/actions:

Deep firewall design often mixes:

Stateful Firewalls and Connection Tracking

Linux firewalls are stateful by default using the connection tracker (conntrack):

You can match connection state (iptables) with:

Views: 24

Comments

Please login to add a comment.

Don't have an account? Register now!