bknd logo

UFW

How to set up UFW on your Linux server

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.

Installation

To install UFW, use the following command:

sudo apt install ufw

Enabling UFW

To enable UFW, run:

sudo ufw enable

Allowing Connections

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

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

You can also specify port numbers directly, like so:

sudo ufw allow 8080/tcp

Denying Connections

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:

sudo ufw deny 23

Allowing Specific IP Addresses

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

Checking UFW Status

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

sudo ufw status

Disabling UFW

To disable UFW, you can run:

sudo ufw disable

Resetting UFW

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

sudo ufw reset

Deleting Rules

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:

sudo ufw delete allow http

You can also delete entries using this method:

ufw status numbered

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

ufw delete <nmbr>

Conclusion

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.