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:

  1. Install UFW: Open a terminal and run the command sudo apt-get install ufw to install UFW.
  2. Enable UFW: Run the command sudo ufw enable to enable UFW. This will set the default policy to deny all incoming connections and allow all outgoing connections.
  3. 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 command sudo ufw allow 22/tcp.
  4. 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 command sudo ufw deny 80/tcp.
  5. 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 command sudo ufw allow from 192.168.0.100.
  6. Check the firewall status: Run the command sudo ufw status to check the current firewall status, including the rules that are currently in place.
  7. Enable logging: To enable logging, run the command sudo ufw logging on. This will log all UFW-related events to the system log.

Please note that these commands are for a basic setup, you can customize the firewall rules to fit your needs and also consider disabling incoming traffic for all interfaces except for the ones you are currently using.

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.

Leave a Comment