In plain English A gatekeeper that decides which connections are allowed into a server and blocks the rest.
A firewall decides which network connections may reach a computer, and which it may make. On a server, the main job is blocking incoming connections to every service except those meant to be public: typically SSH on portPort A numbered door on a server. Each service listens behind its own door: web pages on 443, email on others, remote login on 22. More about Port → 22 and the web server on ports 80 and 443.
Kinds of firewall
| Kind | Where it runs | Examples |
|---|---|---|
| Host firewall | On the server itself | UFW (Ubuntu, Debian), firewalld (AlmaLinux, Rocky, Fedora) |
| Network firewall | In front of the server, in the provider’s network | Cloud “security groups” and firewall rules |
| Web application firewall | Inspects web requests for attacks | ModSecurity, CDN security rules |
Host and network firewalls filter by address and port. A web application firewall reads the content of web requests and blocks patterns such as SQL injection attempts.
A minimal server setup
On Ubuntu:
sudo ufw allow OpenSSH
sudo ufw allow 80,443/tcp
sudo ufw enable
Always allow SSHSSH A secure way to type commands on a server from your own computer, as if you were sitting at it. More about SSH → before enabling the firewall, or you lock yourself out. Services such as databases should listen only on 127.0.0.1 as well as being blocked, so a firewall mistake does not expose them.
When something is “open on the server but unreachable”, check both the host firewall and the provider’s network firewall. Full steps are in how to set up a firewall on Linux.