Lesson 01 Packet Filtering: from iptables to nftables
Theme:

Homework — Lesson 01

~15 min · Two tasks · Bash only

Task 1 — Allow only SSH and HTTP, drop everything else

Using iptables, write rules that:

  1. Allow inbound SSH (TCP/22) from anywhere.
  2. Allow inbound HTTP (TCP/80) from anywhere.
  3. Allow established/related return traffic.
  4. Drop everything else inbound.
  5. Allow all loopback traffic.

Self-check:

Task 2 — Translate to nftables and persist

Recreate the same firewall using nftables:

  1. Create a table and an input chain hooked at filter priority 0.
  2. Add the four rules from Task 1.
  3. Save the ruleset: sudo nft list ruleset > rules.nft.
  4. Flush, then reload from file: sudo nft flush ruleset && sudo nft -f rules.nft.

Self-check:

View solutions →