Blog, News & Events

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:

sudo apt update && sudo apt upgrade -y

Step 2: Check if UFW is Installed

Most Ubuntu distributions come with UFW pre-installed. Check its status with:

sudo ufw status

If it’s not installed, run:

sudo apt install ufw -y

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.

sudo ufw allow ssh

For custom SSH ports (e.g., 2222):

sudo ufw allow 2222/tcp

Step 4: Enable Common Services

Allow other necessary services depending on your VPS usage:

  • For HTTP (websites):

    sudo ufw allow http
  • For HTTPS (secure websites):

    sudo ufw allow https
  • For DNS (if running a DNS server):

    sudo ufw allow 53

Step 5: Enable UFW

Now, enable UFW with:

sudo ufw enable

Check the status:

sudo ufw status verbose

Step 6: Deny Unwanted Traffic

By default, UFW blocks all incoming connections except the ones you explicitly allow. You can also deny specific ports:

sudo ufw deny 23 # Blocks Telnet (insecure protocol)

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:

sudo ufw allow from 192.168.1.100 to any port 22

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.

Leave a Reply

Your email address will not be published.