Configuring UFW Firewall on Ubuntu VPS: A Step-by-Step Guide
When running a VPS (Virtual Private Server), security should always be your top priority. One of the easiest and most effective ways to secure your server is by configuring a firewall. Ubuntu comes with UFW (Uncomplicated Firewall), a user-friendly tool for managing firewall rules without the complexity of iptables.
In this guide, we’ll walk you through the process of configuring UFW firewall on Ubuntu VPS. Whether you are hosting a website, running applications, or managing sensitive data, this setup will help keep your server safe.
👉 At Sternhost VPS Hosting, all our VPS servers support UFW, making it easy for you to secure your hosting environment.
Step 1: Update Your System
Before making any changes, ensure your Ubuntu server is up-to-date:
Step 2: Check if UFW is Installed
Most Ubuntu distributions come with UFW pre-installed. Check its status with:
If it’s not installed, run:
Step 3: Allow SSH Connections
Since you’ll be managing your VPS remotely, you must allow SSH before enabling UFW. Otherwise, you risk locking yourself out.
For custom SSH ports (e.g., 2222):
Step 4: Enable Common Services
Allow other necessary services depending on your VPS usage:
-
For HTTP (websites):
-
For HTTPS (secure websites):
-
For DNS (if running a DNS server):
Step 5: Enable UFW
Now, enable UFW with:
Check the status:
Step 6: Deny Unwanted Traffic
By default, UFW blocks all incoming connections except the ones you explicitly allow. You can also deny specific ports:
Step 7: Advanced Rules (Optional)
For added security, you can allow connections only from specific IPs. For example, to allow SSH only from your office IP:
Conclusion
By following these steps, you have successfully configured the UFW firewall on your Ubuntu VPS. This ensures that only essential services are accessible, reducing the risk of cyber-attacks and unauthorized access.
At Sternhost, our VPS hosting plans are optimized for performance and security, giving you a reliable environment to run your projects with peace of mind.
For more security tips, check out Ubuntu’s UFW Documentation.
✅ With UFW configured, your Ubuntu VPS is now significantly more secure.