
ufw (Uncomplicated Firewall) is Ubuntu’s simple firewall: it shuts everything coming in and opens only what you tell it. The golden rule fits in one line: open the SSH port first, switch on afterwards. Turning ufw on without that rule shuts the very door you are coming in through, and it is the number one cause of people losing access to a server (see I have lost SSH access to my server). The commands are yours, on your own server: support does not run them for you (see how far our support goes).
Step by step
|
|
|
|
|
|
Rules you will want next
| I want to… | Command |
| Limit SSH attempts | sudo ufw limit ssh (it refuses an address that tries to connect too many times in a short while) |
| Let SSH in only from my address | sudo ufw allow from 203.0.113.5 to any port 22 proto tcp (the address is an example; swap in yours, and remove the more open SSH rule) |
| See the numbered rules | sudo ufw status numbered |
| Delete a rule | sudo ufw delete 3 (the number from the list) |
| Switch the firewall off | sudo ufw disable |
| Start again from scratch | sudo ufw reset (deletes every rule and switches it off) |
| Docker ignores ufw. A port published by a container (-p 8080:80) is open to the world even with no ufw rule, because Docker writes its own rules. See ports and firewall on a VPS: why your app is not reachable. AlmaLinux and Rocky do not use ufw but firewalld, explained in the same article. |
| If you got locked out, the panel console fixes it. Through the console, sudo ufw disable switches the firewall off and lets you back in, to correct the rules at leisure. If with the port open on the server you still cannot connect, there may be another firewall outside the server, on the network: tell us and we will look from our side. See keeping your VPS secure: the six that matter. |
|
Switched the firewall on and lost access? Tell us the VPS address and the rule you were applying. Open a support ticket |
RECOMMENDED PRODUCT Web hosting with cPanel Domain and SSL included, daily backups and the panel you already know. from £5.28/mo (3-year plan, with coupon) See plans |
- 0 Users Found This Useful











