ufw
the firewall, made simpleufw — uncomplicated firewall — writes the iptables or nftables rules for you. It blocks incoming connections by default and lets you open ports by name or number, and its rules are saved and applied again at boot.
Allow SSH before you enable it: ufw allow ssh, then ufw enable.
At the terminal
Read the session first, then the notes: each numbered line in the output is answered by the note with the same number.
What the numbered lines are telling you
ufw looked "ssh" up as port 22 and added it for both protocols at once — something iptables needs two commands for.
The warning is real: enabling the firewall without the SSH rule would cut you off. It is safe here because the rule was added first.
Incoming connections are denied unless a rule allows them; outgoing ones are allowed.
Port 22 is open to anyone, over both IPv4 and IPv6. Nothing else is.
Switches
A switch changes how the command behaves. These are the ones used day to day; man ufw lists the rest. Single-letter switches can usually be joined, so -l -a may be written -la.
enable- Turn the firewall on, now and at boot. "disable" turns it off.
status verbose- Show the state, the defaults and every rule.
allow PORT- Allow incoming connections to a port or named service.
deny PORT- Block incoming connections to a port.
limit PORT- Allow, but rate-limit repeated connections.
delete NUM- Delete a rule by its number.
--dry-run- Show the rules that would be written without applying them.
Variations worth knowing
The same tool, pointed at a narrower question. These four cover most of what it is reached for day to day.
sudo ufw allow from 192.168.1.0/24 to any port 22Allows SSH only from the local network.
sudo ufw status numberedLists rules with numbers, for deleting.
sudo ufw delete 2Deletes rule number 2.
sudo ufw limit sshAllows SSH but blocks an address that connects too often — a simple brake on password guessing.
In cybersecurity
The value of ufw is that a correct default-deny firewall takes three commands.
Each allowed port is a service exposed. Restrict administrative ports to the addresses that need them rather than to Anywhere.
Ports published by Docker containers are opened by Docker’s own rules and are reachable even when ufw says otherwise. Bind them to 127.0.0.1 or filter in the DOCKER-USER chain.
A firewall rule is a claim. Scanning the machine from another host with nmap is the proof.