Security

UFW

UFW (Uncomplicated Firewall) is a user-friendly front-end for managing iptables firewall rules. It provides an easy-to-use interface for configuring and managing firewall rules on Linux systems, making it simpler to secure your server and control incoming and outgoing network traffic.

UFW Setup

Installation

To install UFW, use the following command:

bash
sudo apt install ufw

Enabling UFW

To enable UFW, run:

bash
sudo ufw enable

Allowing Connections

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

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

You can also specify port numbers directly, like so:

bash
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:

bash
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 192.168.1.100:

bash
sudo ufw allow from 192.168.1.100

Checking UFW Status

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

bash
sudo ufw status

Disabling UFW

To disable UFW, you can run:

bash
sudo ufw disable

Resetting UFW

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

bash
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:

bash
sudo ufw delete allow http

You can also delete entries using this method:

bash
ufw status numbered

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

bash
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.