{"canonical_url":"https://engineer.company/glossary/firewall/","content_markdown":"# Firewall\n\n## What it is\n\nA firewall is a filter on a network path that compares each packet or\nconnection with a list of rules and then lets it through, drops it or answers\nwith a refusal. It can be software on the machine it protects, a separate\nappliance between two networks, or a service a cloud provider runs in front of\na virtual machine. Linux administrators often say packet filter for the same\nthing, and cloud providers sell firewalls under names such as security group.\nIn plural, firewalls usually come in layers: one at the provider, one on the\nhost.\n\nNIST's guidance on the subject, SP 800-41 Rev. 1 from September 2009, sorts\nthem by how much of the traffic they read. A packet filter looks at addresses,\nprotocol and port numbers, one packet at a time. A stateful firewall also\nremembers connections, so the reply to a request the server made itself comes\nback in without a rule of its own. An application-proxy gateway terminates the\nconnection and reads the protocol inside it. A host-based firewall runs on the\nserver or laptop it guards and knows which program owns a socket.\n\nOn a Linux server the filtering happens in the kernel's netfilter framework.\nnftables, available since kernel 3.13, replaces the older iptables tools, and\nfront ends such as ufw write the rules for people who would rather state\nintent than chains. Whatever writes them, the model is the same: an ordered\nlist, read from the top, where the first rule that matches decides.\n\nA firewall is often confused with neighbouring tools. A web application\nfirewall reads HTTP requests and blocks attack patterns in them; a network\nfirewall never looks that deep. An intrusion-banning tool reads logs and adds\ntemporary rules against addresses that misbehave, which means it depends on a\nfirewall underneath. A VPN decides who is on the network at all. Each of them\nanswers a different question, and none replaces the plain rule list.\n\n## Why it matters\n\nEvery service that listens on a public address is a door, and the firewall is\nthe inventory of which doors exist. The decision a team actually faces has\nthree parts: where the firewall lives, what it allows by default, and who is\nallowed to change it.\n\nA provider firewall stops traffic before it reaches the machine, keeps working\nif someone gains root on the host, and costs the server nothing in CPU. Its\nrules live in a console or an API, outside the server's own configuration, so\nthey drift unless they are written as code. A host firewall travels with the\nmachine, can rate-limit a single port and can be tested from the machine\nitself, but a compromised root account can rewrite it, and so can software\nthat manages its own rules. Running both is common and sensible, at the price\nof keeping two lists in step: every port opened or closed is a change in two\nplaces.\n\nThe default is the second part. NIST recommends denying all traffic that is\nnot expressly permitted, and for inbound traffic almost everyone agrees.\nOutbound filtering is where the trade-off bites: it limits what a compromised\nservice can reach, and it breaks package updates, certificate renewal and\nmonitoring until each destination has its rule.\n\nThe third part is ownership. A firewall in default-deny mode is only as\ncorrect as the list of ports someone declared, so the useful artefact is that\ndeclared list, kept in version control and checked against the live rules.\nThe software is free on every mainstream Linux distribution; what costs money\nis the attention needed to keep the declaration true. And a firewall is a\nsecond line. A service bound to the loopback address cannot be reached from\noutside whatever the rules say, which is a stronger guarantee than a deny\nrule in front of a service listening everywhere.\n\n## What it looks like in practice\n\nOn one host a rate limit for the SSH port sat in the rule list for a year\nwithout a single packet reaching it, because a broader allow above it matched\nfirst. The status tools listed the limit all year, and they were right to: it\nexisted.\n[The checks were rewritten to read rule position rather than presence](/portfolio/verified-firewall-rules-by-position/):\nthey now compare the order of the numbered rules, and of the chain the kernel\nis actually filtering with, against what was intended. Every port gets one\nrule and every rule names a protocol; SSH is rate-limited and has no separate\nallow. The five public ports are declared together and checked as a set, so an\nopen port the declaration leaves out turns the check red, and the security\nreport lists the rules in the order packets meet them, with a note on how to\nread that order.\n\nThe first server was built by hand and only later got its firewall, which\nleft a window in which a fresh machine was reachable from the internet. For a\nsecond server at a different provider,\n[the firewall is created by its own play ahead of the machine](/portfolio/provisioned-a-second-server-from-code/),\nso the new machine meets the internet with its rules already in place. That\nprovider attaches firewalls by tag, so the tags are created first: a rule\naimed at a tag needs the tag to exist. Each provider's firewall is written\ndirectly against that provider's REST API with a plain HTTP task. The task\ndoes nothing in a dry run, so changes are rehearsed on the firewall play\nitself, since a provider firewall costs nothing to create and can be deleted\nagain.\n\nContainers can get past a firewall without touching it. Docker writes its own\nentries into the kernel's packet filter, and a port it publishes for a\ncontainer is matched before anything the host's hardening role put there, so a\ncontainer can be reachable from outside whatever the firewall was told.\n[This platform's containers run under systemd through Podman and Quadlet](/portfolio/ran-containers-on-podman-and-quadlet/),\nshare the host's network and publish no ports, so there is no container port\nfor anything to route around the rules.\n\n## Where it goes wrong\n\n**A rule appears in the status output and never fires.** Rules are evaluated\nin order and the first match wins, so a broad allow placed above a narrower\nlimit or deny shadows it completely. The listing still shows both. Read the\nrules as the kernel does, numbered and in order, put specific rules above\ngeneral ones, and test from a machine outside:\n\n```sh\nufw status numbered\nnft list ruleset\n```\n\n**A container answers on a port the firewall denies.** Docker publishes ports\nby redirecting traffic in the kernel's NAT table, before it reaches the chains\nufw filters, and Docker's own documentation says this effectively ignores the\nfirewall configuration. Publish to the loopback address only, put a provider\nfirewall in front, or run containers without published ports as described\nabove.\n\n**IPv4 is locked down and IPv6 is wide open.** The two address families have\nseparate rule sets in iptables, and ufw writes IPv6 rules only when IPv6 is\nenabled in its defaults file. A host with a public IPv6 address and an\nIPv4-only rule set is exposed on every port it listens on. Use an nftables\ntable of the `inet` family, which sees both, or audit both listings, and scan\nthe host's IPv6 address from outside.\n\n**The SSH session freezes the moment the firewall is enabled.** Default deny\nwent live before the rule for SSH, or the SSH daemon was moved to another port\nwhile the rule still names 22. Add the SSH rule first, keep the provider's\nconsole open in another window, and schedule an automatic rollback a few\nminutes out that is cancelled once a new session gets in.\n\n**A rule opens more than its author meant.** In ufw, a rule that names a port\nwithout a protocol opens it for both TCP and UDP. Name the protocol on every\nrule, and declare the expected surface as a whole so that anything extra fails\na check rather than waiting for an audit.\n\n## Further reading\n\n- [Firewall](https://csrc.nist.gov/glossary/term/firewall)\n  — the definitions NIST publications use, each linked to its source document.\n- [SP 800-41 Rev. 1: Guidelines on Firewalls and Firewall Policy](https://csrc.nist.gov/pubs/sp/800/41/r1/final)\n  — firewall types, default-deny policy and rule management, from NIST.\n- [ufw(8)](https://manpages.ubuntu.com/manpages/noble/man8/ufw.8.html)\n  — Ubuntu's firewall front end, including rule order and the `limit` rule.\n- [nftables wiki](https://wiki.nftables.org/wiki-nftables/index.php/Main_Page)\n  — the netfilter project's documentation for the framework that replaces\n  iptables.\n- [Packet filtering and firewalls](https://docs.docker.com/engine/network/packet-filtering-firewalls/)\n  — Docker's own account of how published ports pass around a host's rules.\n\n\u003chttps://engineer.company/glossary/firewall/\u003e\n","date_modified":"2026-10-20T21:59:50Z","description":"Host or cloud firewall, why rule order outweighs rule count, and the gaps that keep a port open behind a status listing that looks clean.","formats":{"gemtext":"https://engineer.company/glossary/firewall/index.gmi","gopher":"https://engineer.company/glossary/firewall/gophermap","html":"https://engineer.company/glossary/firewall/","json":"https://engineer.company/glossary/firewall/index.json","markdown":"https://engineer.company/glossary/firewall/index.md","pdf":"https://engineer.company/glossary/firewall/index.pdf"},"kind":"page","language":"en","title":"What is a firewall?","url":"https://engineer.company/glossary/firewall/","version":1}