What does a firewall actually check?
At the simplest level, each packet carries a source address, a destination address, a protocol and, for TCP and UDP, port numbers. A firewall compares those fields with its rules and decides to accept, drop or reject the packet. Dropping discards it silently, so the sender waits and times out; rejecting sends back an error, which is friendlier for legitimate users but tells a scanner that something is there. More advanced firewalls also look at connection state, the content of the request, or the identity of the user behind it.
Which types of firewall exist?
| Type | Looks at | Example |
|---|---|---|
| Stateless packet filter | Each packet alone, headers only | Router access lists |
| Stateful firewall | Headers plus the connection each packet belongs to | nftables with conntrack |
| Application or proxy firewall | Content of a specific protocol such as HTTP | A web application firewall |
| Next-generation firewall | Apps, users and attack signatures | Gateway with IPS |
| Host firewall | Traffic to and from one machine | ufw, firewalld, Windows Defender Firewall |
Next-Generation Firewall and Web Application Firewall go deeper into the last categories.
How does connection tracking make rules simpler?
Without state, allowing your server to fetch updates means also allowing any inbound packet with a source port of 443, which is easy to abuse. With connection tracking, the kernel remembers each flow your machine started. One rule, accept established and related, then covers every reply, and the inbound side can stay closed except for the services you publish. You can watch the table with conntrack -L | head after installing the conntrack tool, and see its size limit with sysctl net.netfilter.nf_conntrack_max.
Which firewall tools come with Linux?
- nftables: the current kernel framework and the native tool on Debian 12 and 13, Ubuntu, AlmaLinux and Rocky Linux 9.
- iptables: the older interface, now usually a compatibility layer that writes nftables rules underneath. iptables basics covers its syntax.
- ufw: a friendly front end on Ubuntu and Debian for common allow and deny rules.
- firewalld: the default on the Red Hat family, organized around zones and named services.
Use one front end per machine. Running ufw and firewalld together, or mixing hand-written nftables files with either, leads to rules that seem to vanish after a reload.
What does a sensible first ruleset look like?
Default deny inbound, allow loopback, allow replies, allow ping, then open only what the box serves. With firewalld on AlmaLinux:
firewall-cmd --get-default-zone firewall-cmd --permanent --zone=trusted --add-source=198.51.100.7/32 firewall-cmd --permanent --zone=public --add-service=http --add-service=https # the shop answers on 80 and 443 firewall-cmd --permanent --zone=public --remove-service=cockpit --remove-service=ssh firewall-cmd --reload && firewall-cmd --zone=public --list-all
Put your own address into the trusted zone before removing the general SSH service, and keep a second session open while you test. If you do lock yourself out, a reboot from the panel will not undo permanent rules, so a reinstall would be the fallback; careful ordering avoids that.
How do I keep rules across reboots?
Each front end has its own save path. ufw and firewalld store their state automatically when you use --permanent or the ufw commands. With raw nftables, write the ruleset to /etc/nftables.conf, check it with nft -c -f /etc/nftables.conf, and enable the loader with systemctl enable nftables. A quick test after any change: reboot from the panel during a quiet hour and confirm the listing matches what you expect.
Where do firewalls sit around one of our machines?
Two layers. At the network edge, DDoS filtering absorbs floods aimed at your address before they reach the ports, described on Edge DDoS filtering. On the machine, the host firewall you configure decides which services are reachable. There is no separate managed firewall appliance in the order, and you do not need one for most setups: a tidy host ruleset plus services bound to loopback covers the common risks. Perimeter Firewall shows how to extend the boundary across several machines.
Which mistakes do people make most often?
- Opening a database port to the world for a quick remote test and forgetting it.
- Assuming container port mappings respect host rules; Docker inserts its own chains, so publish to 127.0.0.1 when only a local proxy needs access.
- Blocking all ICMP, which breaks path MTU discovery and causes stalled transfers.
- Saving rules with one tool and loading another at boot, so a reboot silently reverts the setup.
Does a firewall need powerful hardware?
Not for host filtering. The cheapest E1 filters its 2x 1 Gbps links without noticeable load. Heavier work, such as connection tracking for millions of flows on a busy gateway, mainly wants memory for the conntrack table, where a box like the S5 with 128 GB DDR4 has lots of room.
Machines Where a Host Firewall Is All You Need
| Server | Processor | Cores / threads | Memory | Storage | Network | Per month | Smallest order |
|---|---|---|---|---|---|---|---|
| E1 | Intel Xeon E3-1240 v3 | 4 / 8 | 16 GB DDR3 | 2x 240 GB SSD | 2x 1 Gbps | $30.52 | $91.56 (3 months) |
| S1 | Intel Xeon E-2276G | 6 / 12 | 64 GB DDR4 | 1x 1 TB NVMe | 2x 10 Gbps | $53.32 | $53.32 (1 month) |
| S5 | Intel Xeon E-2276G | 6 / 12 | 128 GB DDR4 | 2x 1 TB NVMe | 2x 10 Gbps | $88.72 | $88.72 (1 month) |
Keep Reading
Perimeter Firewall
The filter at the edge between a trusted network and the internet, how the idea maps onto one rented machine, and its limits.
OpenNext-Generation Firewall
Firewalls that look past ports to applications, users and threats, what NGFW features really do, and the open source pieces that cover them.
Openiptables basics
How iptables tables, chains and targets fit together, plus a minimal default-deny rule set for a new bare metal server.
OpenSet up fail2ban
Install fail2ban, write a jail.local for SSH and nginx, read the ban list and unban an address you locked out by mistake.
OpenFAQ
Quick Answers
Drop discards a packet silently, so the sender times out. Reject sends back an error, so the sender learns at once that the port is closed.
ufw is easier for simple allow lists. nftables gives full control. Both write kernel nftables rules, so pick one and stay with it.
No. Some ICMP messages are needed for path MTU discovery. Allow at least echo requests and the error types the kernel needs.
Docker adds its own forwarding rules that run before ufw. Publish container ports on 127.0.0.1 and front them with a reverse proxy.
Yes. Edge filtering stops floods, while the host firewall decides which services may be reached at all.