Labs / Sealed Lines / ACLs & firewalls

Lab 3 of 3 · ACLs & firewalls

A stateful firewall: replies come home, nothing new gets in

Build a stateful firewall that lets replies home while keeping new connections out.

Open this lab Pro 4 steps

The idea

A stateful Firewall remembers the connections it let out, so their replies come home and nothing new comes in. You build one on firewall, between insideClient and insideServer on one side and outsideClient and outsideServer on the other.

A reply looks like a new connection
A reply looks like a new connection
Who started it decides
Who started it decides

Steps

  1. The inside reaches out

    Build a stateful firewall from nothing, starting with rules that judge each packet alone, to see why that is not enough. First the plain part: accept whatever the inside sends, and drop everything else with the FORWARD policy.

    firewall:~# iptables -A FORWARD -i insideNetwork -j ACCEPT
    firewall:~# iptables -P FORWARD DROP
    insideClient:~# curl -sS -m 4 http://outsideServer.lab/
  2. Replies need state

    A reply is a packet from the outside too, so the firewall must remember what it let out to tell the two apart. Above step 1's rules, put a line that accepts packets of a connection the firewall already let through: established, by its connection tracking.

    firewall:~# iptables -I FORWARD 1 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
    insideClient:~# curl -sS -m 4 http://outsideServer.lab/
    firewall:~# conntrack -L -p tcp --dport 80

Pro

2 more steps in the app

  1. The outside is shut out
  2. It is the direction, not the host
Get Pro

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Start with a free account: Google or email, no card.

Open this lab