Skip to main content
A firewall is a software or hardware security guard that sits between your system and the internet. It inspects and controls network traffic flowing in and out of a host or network to block unwanted access and reduce attack surface.
An infographic showing a computer behind a dashed boundary protected by a brick-and-shield firewall icon between it and a wireless router. A caption reads, "It acts like a barrier between the system and the internet."
Think of a firewall like a home security system: it watches doors and windows and only lets approved people in. Firewalls can be implemented as host-level software (common on personal and server OSes) or as dedicated hardware appliances in data centers. Linux distributions expose firewall management tools as friendly front-ends to the kernel packet-filtering system (historically iptables, increasingly nftables). For example:
  • Debian / Ubuntu: UFW (Uncomplicated Firewall)
  • Red Hat / Fedora / CentOS: Firewalld
Both tools configure the kernel packet filters; the kernel enforcement is what actually permits or blocks packets.
A slide titled "Firewall" showing Red Hat and Fedora logos side by side, with bullet notes mentioning installing via YUM and that iptables comes pre-installed in Linux distros.
Windows and macOS include built-in firewalls as well. Windows Firewall is typically enabled by default; macOS firewall must usually be enabled manually. Whatever platform you use, enable the firewall and only allow the traffic you need. Ports — what are they? A port is a network communication endpoint used by services on a computer. If a computer is a house, ports are the doors and windows. Close the ones you don’t need and only open the ones required by your services. For web traffic these are:
A diagram titled "Common Ports" showing client computers routed through a Web Application Firewall (a brick wall with flames) to origin servers. Two clients are allowed (green checkmarks) while a malicious client is blocked (red X) by the WAF.
You don’t need to memorize every port number, but know 80, 443, and 22. For servers exposed to the public internet, generally only open the web ports (80/443) and any management port (like SSH) restricted to trusted IPs. If you must open additional ports, prefer IP whitelisting or VPN access over broad exposure.
Avoid opening ports to “anywhere” unless absolutely necessary. Exposing management ports to the internet increases risk—use IP allowlists, SSH keys, or a VPN.
Managing UFW (Debian / Ubuntu) Before enabling UFW on a remote machine, allow SSH so you don’t lock yourself out.
Always allow SSH first. Example: sudo ufw allow 22/tcp before running sudo ufw enable on a remote server.
Common UFW commands:
Notes:
  • Use sudo ufw status numbered to see rule indices and remove rules safely.
  • UFW is deliberately simple — it’s suitable for host-level firewalling and quick rule management.
Managing Firewalld (Red Hat / Fedora / CentOS) If Firewalld is not installed, use your package manager to install and then start and enable it for boot persistence. Use firewall-cmd with --permanent for persistent rules, then --reload to apply them immediately. Common Firewalld commands:
Notes:
  • --permanent changes the persistent configuration; --reload applies changes to the running runtime.
  • You can enable and start Firewalld in one command with sudo systemctl enable --now firewalld.
Quick comparison: UFW vs Firewalld Inspecting listening ports with netstat / ss Tools like netstat (from net-tools) or ss (from iproute2) show which services are actually listening on ports — they do not show firewall rules. Install net-tools if needed:
List listening sockets:
Explanation of options:
  • -n show numeric addresses/ports
  • -l show listening sockets
  • -t show TCP
  • -u show UDP
  • -p show PID/program name
Important distinctions:
  • netstat / ss show which services are bound to ports (i.e., listening). If no service is listening on a port, opening that port in the firewall does not make the service available.
  • Firewall tools (UFW / Firewalld) control whether packet flows can reach those services. Both pieces must be configured correctly for a service to be reachable from the network.
Useful links and references You can run the commands shown above to confirm which ports your services are listening on and which ports are allowed by your firewall.

Watch Video