Ubuntu 22.04 Set Up UFW Firewall in 10 Minutes
The Uncomplicated Firewall (UFW) is a firewall management tool for Ubuntu that makes it easy to set up and configure a firewall. Here's a quick guide on how to set up a firewall using UFW on Ubuntu 22.04:
- Install UFW: Open a terminal and run the command
sudo apt-get install ufwto install UFW. - Enable UFW: Run the command
sudo ufw enableto enable UFW. This will set the default policy to deny all incoming connections and allow all outgoing connections. - Allow incoming connections: To allow incoming connections on specific ports, you can use the command
sudo ufw allow <port number>/<protocol>. For example, to allow incoming connections on port 22 (SSH) run the commandsudo ufw allow 22/tcp. - Deny incoming connections: To deny incoming connections on specific ports, you can use the command
sudo ufw deny <port number>/<protocol>. For example, to deny incoming connections on port 80 (HTTP) run the commandsudo ufw deny 80/tcp. - Allow incoming connections from specific IPs: To allow incoming connections from specific IPs, you can use the command
sudo ufw allow from <IP address>. For example, to allow incoming connections from IP address 192.168.0.100 run the commandsudo ufw allow from 192.168.0.100. - Check the firewall status: Run the command
sudo ufw statusto check the current firewall status, including the rules that are currently in place. - Enable logging: To enable logging, run the command
sudo ufw logging on. This will log all UFW-related events to the system log.
Also, before making any changes to your firewall, it's recommended to have a backup plan in case something goes wrong, and also to test the changes before applying them to your production environment.
