# Firewall

> A filter that lets some network traffic through and blocks the rest.

**Field:** Infrastructure  
**Category:** Security  
**Also known as:** Network Firewall, Host Firewall, Firewall Rule

## Think of it like

It is like a guard at a gate with a list. Only people on the list may come in.

## Definition

A firewall is a filter that decides which network traffic may pass. It follows a list of rules. A rule can allow or block traffic by where it comes from, which port it uses or which way it goes. Most firewalls block all traffic coming in unless a rule allows it. A firewall can be a box on the network or a program on one computer.

## Example

Jack's web server only needs ports 22, 80 and 443 open. His firewall blocks every other port. So a database left on by mistake cannot be reached from outside.

## Example code

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

On Ubuntu, UFW sets up a firewall. Block all incoming traffic, then allow only SSH and HTTPS.

## Why it matters

Every open port is a door. A firewall keeps the doors you did not mean to open shut.

## Common mistake

Turning the firewall on over a remote link before allowing SSH. It locks you out of your own server.

## Three principles

- **Rules decide.** Allow or block by address, port and direction.
- **Deny by default.** Block all, then open what is needed.
- **One layer.** It does not stop attacks on open ports.

## Related terms

- [Virtual Private Network (VPN)](https://learn.benibix.com/term/infrastructure/vpn)
- [Zero Trust](https://learn.benibix.com/term/infrastructure/zero-trust)
- [Distributed Denial of Service (DDoS)](https://learn.benibix.com/term/infrastructure/ddos-attack)
- [Network Port](https://learn.benibix.com/term/infrastructure/port)
- [Internet Protocol Address (IP Address)](https://learn.benibix.com/term/infrastructure/ip-address)
- [Cloud Firewall](https://learn.benibix.com/term/infrastructure/cloud-firewall)

## Told apart from

- [Firewall vs VPN](https://learn.benibix.com/compare/firewall-vs-vpn): People think a VPN and a firewall do the same job, and they do not. A firewall is a filter at the edge of a network. It lets some traffic in and blocks the rest. A VPN is a locked tunnel that carries your traffic across the internet so nobody on the way can read it. Many networks use both.
- [Firewall vs Antivirus Software](https://learn.benibix.com/compare/firewall-vs-antivirus): People think a firewall and antivirus do the same job. A firewall decides which traffic may come in or go out. It looks at ports and addresses, not inside files. Antivirus checks the files and programs on a computer and stops bad ones. One guards the door. The other checks what is already inside.

## Taught in

- [UFW and Linux Firewalls](https://learn.benibix.com/learn/infrastructure-linux/ufw-and-linux-firewalls): Linux CLI, 10/10
- [Cloud Firewall and Floating IP](https://learn.benibix.com/learn/infrastructure-vps/cloud-firewall-and-floating-ip): VPS, 6/7

![The internet on the left, an office network on the right. A firewall sits between them, letting web traffic through and blocking the rest. Below, a laptop away from the office reaches the office network through a locked tunnel marked VPN that runs across the internet.](https://learn.benibix.com/diagrams/inf-firewall-vpn.svg)

---

Source: https://learn.benibix.com/term/infrastructure/firewall
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
