Setting Up a Firewall with UFW on Ubuntu

UFW (Uncomplicated Firewall) is a simple and effective way to manage firewall rules on Ubuntu. It provides an easy-to-use command-line interface to control incoming and outgoing network traffic, helping you secure your server and network.

← Back

Step 1: Install UFW

UFW is usually pre-installed on most Ubuntu systems. If it's not, you can install it using the following command:

sudo apt install ufw

Step 2: Allow SSH Connections

Before enabling the firewall, you should allow SSH connections to avoid being locked out of the server:

sudo ufw allow OpenSSH

Step 3: Enable UFW

Activate the firewall by running:

sudo ufw enable

You can check UFW's status using:

sudo ufw status

Step 4: Allow Common Ports

Allow traffic on ports 80 (HTTP) and 443 (HTTPS) for web services:

sudo ufw allow 80
sudo ufw allow 443

Step 5: Deny All Other Incoming by Default (Optional)

You can set the default policy to deny all incoming connections and allow outgoing connections:

sudo ufw default deny incoming
sudo ufw default allow outgoing

Step 6: Check Application Profiles

UFW can detect certain common applications and services. To see the available profiles, use:

sudo ufw app list

Conclusion

By following these steps, you have successfully set up a basic firewall using UFW on your Ubuntu system. Remember to adjust the firewall settings as needed based on the services you are running on your server.

← Back