What is a firewall?
A firewall is a filter that decides which network connections are allowed in or out of a computer or network.
Drafted with AI from official documentation. Scripts were run in a test environment and repository links verified. Awaiting a human check. Did it work for you? Last edited Outdated?
A firewall inspects network traffic and allows or blocks it according to rules. Think of a bouncer at a club door with a guest list: people on the list walk in, everyone else is turned away. Rules are usually written in terms of ports, IP addresses and direction, for example allow port 22 from the office network only.
Every laptop, server and router has one. On Linux you meet ufw, firewalld or raw nftables; cloud providers call theirs security groups. The safest habit is to block everything incoming by default and open only the ports you really serve. When a new service is unreachable from outside but works locally, the firewall is the most likely cause.
Check before you run this
- Runs with administrator rights. Make sure you understand every line.
sudo ufw default deny incoming
sudo ufw allow 22/tcp
sudo ufw enable
See also: What is a port? and What is an IP address?
Did this work for you?
No votes yet. Be the first.
If it did not work, the report form below tells the editors what went wrong.
See also
- 0343 Fix: Connection refused and Connection timed out, what each one means Refused means the host answered and nothing is listening there. Timed out means no answer at all, usually a firewall or wrong… Beginner · Fixes an error · Linux, macOS Article DNS, IP addresses & ports · Firewalls 15 Oct 2026
- 0344 ufw and firewalld: open and close ports Allow and remove ports and services on the two standard Linux host firewalls, restrict a port to one source network, and make… Beginner · Step by step · Linux Article Firewalls · Networking & firewalls 15 Oct 2026
- 0347 Port check script: test a list of host:port pairs with timeouts A bash script that tries a TCP connection to each host:port you give it, waits a few seconds at most, and reports… Beginner · Cheat sheet · Linux, macOS Script DNS, IP addresses & ports · Firewalls 15 Oct 2026
Repos in the wild
- CrowdSec: collaborative intrusion prevention that shares blocklists crowdsecurity/crowdsec CrowdSec reads your logs, detects attacks such as brute force and scanning, blocks the source, and shares anonymised reports so that every participant receives a blocklist built from the whole community. GitHub
- Suricata: a network intrusion detection and prevention engine OISF/suricata Suricata inspects network traffic in real time, matches it against signature rules and protocol logic, and writes alerts and rich protocol logs. It can also sit inline and drop malicious packets. GitHub
History
Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.
- Dominik +793 chars