UFW or ufw is a magnificent little firewall.
Start by checking current status:
sudo ufw status
Status: inactiveAllow for outgoing connections, the default recommendation.
sudo ufw default allow outgoingDeny for incoming connections, the default recommendation.
sudo ufw default deny incomingAllow for SSH connections.
sudo ufw allow sshEnable UFW.
sudo ufw enableCheck the current status:
sudo ufw status verbose
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip
To Action From
-- ------ ----
22/tcp ALLOW IN Anywhere
22/tcp (v6) ALLOW IN Anywhere (v6)The above example has IPv6 enabled, see my separate TIL on that.
There is so much more you can do, I am barely scratching the surface here, but what I want to demonstrate is how easy it is to get started. I have seen UFW referred to as the "Uncomplicated Firewall", and I think that is a very suitable name.