UFW manages host firewall rules on Ubuntu and other systems where it is supported. It can restrict network access to required services, but it does not replace application security or upstream DDoS protection.
Prepare recovery access
Confirm the actual SSH port and the services that must remain accessible. Check provider firewall rules as well as the server’s rules.
Keep the current SSH session open and confirm provider console access before changing rules. Do not run UFW alongside another firewall manager without understanding how they interact.
Add required rules before enabling
Check the existing state:
sudo ufw status verboseFor a server using SSH on port 22 and hosting a public website, these example rules permit those services:
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcpReplace the SSH port if different and add any other required services first. Hosting control panels, DNS and email need additional rules; this example is not a complete control-panel firewall configuration.
For a new, reviewed ruleset, set the intended default policies:
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw enableVerify access
Run sudo ufw status verbose, then open a new SSH session and test the required applications. Check IPv6 rules if the server uses IPv6.
If access fails, use the retained session or console to correct the rules. Do not reset the whole firewall as a routine troubleshooting step.
Optional logging can be enabled with sudo ufw logging on; review its storage use.