What Is a Firewall?

A firewall monitors and controls incoming and outgoing network traffic based on a defined set of security rules, acting as a barrier between trusted and untr...

Published November 18, 2026

A firewall filters network traffic based on rules, allowing or blocking connections by source, destination, port and protocol. It is the first line of defence between a trusted network and an untrusted one.

The concept

Rules are evaluated in order, usually with a default deny: only explicitly allowed traffic gets in. Stateful firewalls track connections and automatically allow replies.

Types include host firewalls (ufw, iptables, Windows Defender), network appliances, cloud security groups and web application firewalls (WAF) that inspect HTTP.

Rule evaluation

filterallowed onlyInternetpacketsFirewallallow/denyServer22, 443 open
Only traffic matching an allow rule passes.

Practical examples

ufw basics

sudo ufw default deny incoming
sudo ufw allow 22/tcp
sudo ufw allow 443/tcp
sudo ufw enable

Allow only your IP for SSH

sudo ufw allow from 203.0.113.5 to any port 22

Cloud security group idea

Inbound: 443 from 0.0.0.0/0 · 22 from office IP only · 3306 from app subnet only

Common mistakes

  • Allowing all inbound by default.
  • Locking yourself out of SSH.
  • Treating the firewall as the only protection.

Key takeaways

  • Default deny, allow what is needed.
  • Stateful tracking handles replies.
  • Layer with other defences.

FAQ

Firewall vs WAF?

A firewall filters network ports; a WAF inspects HTTP for attacks.

Does a firewall stop malware?

Not by itself; it controls connections.

More General articles