UFW (Uncomplicated Firewall) is a simple and effective tool used to manage firewall rules on Linux servers. Install UFW to allow system administrators to easily configure basic firewall rules, offering protection against unauthorized access.
In this guide, we’ll walk you through the steps to install and configure UFW on your Linux server, ensuring a secure environment.
Why Use UFW on Your Linux Server?

Linux servers are often targeted by attackers due to their widespread use and high level of exposure. Implementing a firewall is crucial for blocking unwanted network traffic and controlling access to critical services. UFW is a great choice because it simplifies firewall management, providing an easy-to-use interface to configure iptables rules without the complexity.
UFW is ideal for users who need straightforward firewall protection. It’s simple to configure and doesn’t require advanced networking knowledge. With its pre-configured profiles for common services, UFW is both powerful and easy to use.
Prerequisites
Before installing UFW on your server, ensure you have:
- Root or sudo privileges: You need administrative access to install packages and modify firewall settings.
- Linux distribution: UFW works seamlessly with most Linux distributions, including Ubuntu, Debian, CentOS, and RHEL.
- Internet connection: An active internet connection is required to download the necessary packages.
Install UFW on a Linux Server
Installing UFW is a straightforward process. The following section will guide you through downloading and installing UFW on your Linux system. With just a few commands, you’ll have UFW up and running, protecting your server from unauthorized access.
Update Your Package List
Before installing UFW, make sure your system’s package list is up to date. This ensures you’re installing the latest available version of UFW.
- For Ubuntu/Debian-based systems:
sudo apt update
- For CentOS/RHEL-based systems:
sudo yum update
Updating the package list ensures that your installation pulls the most recent and secure versions of the software.
Check Out | How to Install FirewallD on Linux Server
Install UFW on Linux
Now that your package list is up to date, you can proceed with the installation of UFW. Depending on your distribution, run one of the following commands:
- For Ubuntu/Debian-based systems:
sudo apt install ufw
- For CentOS/RHEL-based systems:
sudo yum install ufw
This command installs UFW along with any dependencies required for it to function correctly. Once the installation is complete, you’re ready to start configuring the firewall.
Enable UFW
After installing UFW, the next step is to enable it. This activates the firewall and begins blocking unwanted traffic based on the default rules.
To enable UFW, run the following command:
sudo ufw enable
Once enabled, UFW will start running immediately and will automatically activate on boot, ensuring your server is always protected.
Configure UFW for Basic Use
At this point, your firewall is up and running. To make UFW effective, you need to define some rules. By default, UFW blocks all incoming traffic and allows all outgoing traffic.
Start by allowing the services you need, such as SSH for remote login:
sudo ufw allow ssh
If you’re running a web server, you’ll also want to allow HTTP and HTTPS traffic:
sudo ufw allow http
sudo ufw allow https
These commands add rules to allow traffic on port 22 (SSH), 80 (HTTP), and 443 (HTTPS). You can continue adding other rules based on the services you need.
Verify UFW Status
To ensure UFW is running properly, you can check its status with the following command:
sudo ufw status
The output should indicate that UFW is active and list the rules that are currently applied to your system. If UFW is not active, you may need to enable it again or troubleshoot any issues preventing it from starting.
Advanced UFW Configuration
For more advanced use, UFW allows you to define additional firewall rules. You can block specific ports or allow traffic from specific IP addresses. For example, to deny access to port 22 (SSH) for security reasons, run:
sudo ufw deny 22
You can also configure UFW to allow traffic only from a specific IP address, like so:
sudo ufw allow from <IP_ADDRESS>
Additionally, UFW has application profiles for popular services like Apache and Nginx, allowing you to configure firewall rules quickly for those services.
Check UFW Logs
UFW maintains a log file that tracks blocked and allowed traffic. You can check these logs to monitor activity and see any unusual attempts to access your server.
To view the log file, use the following command:
sudo less /var/log/ufw.log
This will display detailed logs of blocked or allowed IP addresses and ports. Regularly monitoring these logs helps ensure your firewall is functioning as expected.
Conclusion
UFW is a powerful yet simple tool for securing your Linux server from unwanted network traffic. By following these easy-to-understand steps, you can install and configure UFW to protect your server from unauthorized access. Regular monitoring and adjusting firewall rules based on your server’s needs will help keep your environment secure and reduce the risk of malicious attacks.
With UFW enabled, you’ll have peace of mind knowing that a robust, straightforward firewall solution safeguards your server.