How to Set Up a Basic Firewall Using UFW on Ubuntu

UFW (Uncomplicated Firewall) is an easy-to-use tool for managing a firewall in Linux. It helps protect your server from unauthorized access.

1. Install UFW (If Not Already Installed)

sudo apt update
sudo apt install ufw

2. Allow SSH Access

This ensures you don’t get locked out of your server when enabling the firewall.

sudo ufw allow ssh

3. (Optional) Allow Specific Ports

Examples:

sudo ufw allow 80/tcp   # HTTP
sudo ufw allow 443/tcp  # HTTPS
sudo ufw allow 2222/tcp # Custom SSH port if changed

4. Enable the Firewall

sudo ufw enable

Confirm with y if prompted.

5. Check Status

sudo ufw status

6. Disable or Reset (If Needed)

sudo ufw disable        # To turn it off
sudo ufw reset          # To remove all rules

Summary

UFW is a user-friendly tool that adds a crucial layer of protection to your server. Make sure to only allow necessary ports and keep others blocked for maximum security.

War diese Antwort hilfreich? 0 Benutzer fanden dies hilfreich (0 Stimmen)