Skip to content

UFW Setup

UFW (Uncomplicated Firewall) is a user-friendly interface for managing firewall rules on Linux systems. It simplifies the process of configuring iptables, making it easier to set up and manage firewall rules.

To install UFW, use the following command:

Terminal window
sudo apt install ufw

To enable UFW, run:

Terminal window
sudo ufw enable

To allow connections, which is essential, use the following command:

Terminal window
sudo ufw allow ssh
Terminal window
sudo ufw default deny incoming
sudo ufw default allow outgoing
Terminal window
sudo ufw allow in on tailscale0
optional
sudo ufw allow http
sudo ufw allow https

You can also specify port numbers directly, like so:

Terminal window
sudo ufw allow 8080/tcp

To deny connections to a specific port or service, you can use the deny command. For example, to deny all incoming traffic on port 23 (Telnet), you can run:

Terminal window
sudo ufw deny 23

To allow traffic from a specific IP address, you can use the allow from command. For example, to allow traffic from the IP address `

To check the status of UFW and see which rules are currently applied, use:

Terminal window
sudo ufw status

To disable UFW, you can run:

Terminal window
sudo ufw disable

To reset UFW to its default state, removing all rules, use:

Terminal window
sudo ufw reset

To delete a specific rule, you can use the delete command followed by the rule you want to remove. For example, to delete the rule allowing HTTP traffic, you can run:

Terminal window
sudo ufw delete allow http

You can also delete entries using this method:

Terminal window
ufw status numbered

Check for the number that is related to the rule and then run:

Terminal window
ufw delete <nmbr>

UFW is a powerful tool for managing firewall rules on Linux systems. By following the steps outlined above, you can easily set up and configure UFW to enhance the security of your server. Remember to regularly review and update your firewall rules to ensure that only necessary services are allowed through the firewall.