How to Use UFW on Linux: A Comprehensive Guide
Uncomplicated Firewall (UFW) is a user-friendly frontend for managing iptables firewall rules on Linux systems, mostly Ubuntu 18, Ubuntu 20, Ubuntu 22, Ubuntu 24, Debian 9, Debian 10, Debian 11 and Debian 12. It simplifies the process of securing your server by allowing you to easily configure and manage firewall rules without the need to understand the complexities of iptables. This guide will walk you through how to use UFW on various Linux distributions, including Ubuntu and Debian.
What is UFW and Why Should You Use It?
UFW, short for Uncomplicated Firewall, is designed to make managing a Linux firewall simple and easy. It’s an excellent tool for beginners and experienced users alike, providing powerful features to enhance the security of your Linux system. It is found mostly on Ubuntu 18, Ubuntu 20, Ubuntu 22, Ubuntu 24, Debian 9, Debian 10, Debian 11 and Debian 12.
Key Benefits of UFW
– Ease of Use: UFW offers a straightforward syntax for managing firewall rules.
– Preconfigured Profiles: Many common services like OpenSSH come with pre-configured profiles, making it easy to allow or deny access.
– Integration with iptables: UFW is a frontend for iptables, so it offers the same level of security while being more user-friendly.
How to Install UFW on Debian, Ubuntu, Centos
Before using UFW, you need to ensure it’s installed on your system. Here’s how to install it on various Linux distributions, we will look for it on Centos 7, Centos 9, Ubuntu 18, Ubuntu 20, Ubuntu 22, Ubuntu 24, Debian 9, Debian 10, Debian 11 and Debian 12:
Ubuntu/Debian
UFW is usually pre-installed on Ubuntu and Debian. If it’s not installed, you can install it using:
sudo apt update
sudo apt install ufw
CentOS/RHEL
While UFW is more common on Ubuntu and Debian, you can install it on CentOS/RHEL by enabling the EPEL repository:
sudo yum install epel-release
sudo yum install ufw
How Do I Use UFW on Ubuntu 18, 20, 22, 24?
Using UFW on different versions of Ubuntu is quite similar. Below are the steps to get started:
Allow SSH port before locking yourself out
sudo ufw allow ssh
Enable UFW
sudo ufw enable
Check UFW Status
sudo ufw status verbose
Allow and Deny Ports
sudo ufw allow ssh
sudo ufw deny http
To enable logging of UFW actions, use:
sudo ufw logging on
Disable UFW
sudo ufw disable
These commands work across Ubuntu 18.04, 20.04, 22.04, and the upcoming 24.04 versions. Adjustments may be needed based on specific version nuances, but the basics remain the same.
How Do I Use UFW on Debian 10, 11, 12?
Using UFW on Debian is almost identical to using it on Ubuntu, given their shared Debian base. Here’s how to configure UFW on Debian 10, 11, and 12.
Allow SSH port before locking yourself out
sudo ufw allow ssh
Enable UFW
sudo ufw enable
Check UFW Status
sudo ufw status verbose
Allow and Deny Ports
sudo ufw allow ssh
sudo ufw deny http
To enable logging of UFW actions, use:
sudo ufw logging on
Disable UFW
sudo ufw disable
These commands work across Debian 9, 10 , 11 and 12. Adjustments may be needed based on specific version nuances, but the basics remain the same.
How Do I Use UFW on Centos 7 and Stream 9?
Using UFW on Centos is almost identical to using it on Ubuntu and Debian base. Here’s how to configure UFW on Centos 7 and Stream 9.
Allow SSH port before locking yourself out
sudo ufw allow ssh
Enable UFW
sudo ufw enable
Check UFW Status
sudo ufw status verbose
Allow and Deny Ports
sudo ufw allow ssh
sudo ufw deny http
To enable logging of UFW actions, use:
sudo ufw logging on
Disable UFW
sudo ufw disable
These commands work across Centos 7 and Stream 9. Adjustments may be needed based on specific version nuances, but the basics remain the same.
Common UFW Commands and Tips
Reset UFW to its default state, removing all rules:
sudo ufw reset
List UFW rules with numbers, which is helpful for deleting specific rules
sudo ufw status numbered
Reload UFW
sudo ufw reload
UFW is a powerful yet simple tool for managing your Linux firewall, making it easy to secure your system by controlling network traffic. Whether you are running Ubuntu or Debian, UFW’s user-friendly interface allows you to create, manage, and monitor firewall rules efficiently. By following this guide, you can confidently use UFW to protect your Linux environment.
Remember to regularly review and update your firewall rules to keep your system secure. If you found this guide helpful, consider sharing it with others who might benefit from it!