Interview Prep/Networking/Security: Firewalls, SGs, NACLs & VPN

Docker publishes a port and bypasses your ufw rules. Why?

IntermediateScenarioSecurity: Firewalls, SGs, NACLs & VPN
Answer

Situation read → Docker inserts its own iptables rules ahead of ufw's chains.

What I'd do →

  1. Understand that -p 8080:80 creates DNAT in the nat table and ACCEPT in DOCKER chain, used before ufw's INPUT rules
  2. Check with iptables -L DOCKER-USER -n
  3. Add restrictions in the DOCKER-USER chain: iptables -I DOCKER-USER -i eth0 ! -s 203.0.113.0/24 -j DROP
  4. Or bind to localhost: -p 127.0.0.1:8080:80
  5. Use cloud security groups as the real boundary

Why → Published container ports are forwarded traffic, which doesn't pass through INPUT.

Interview tip → Say you never rely on host firewalls alone for containers.

All Networking questions Roadmap: Networking for DevOps

More on Security: Firewalls, SGs, NACLs & VPN