
{{ $('Map tags to IDs').item.json.title }}
How to Block IPs with ufw
The Uncomplicated Firewall (ufw) is a user-friendly frontend for managing iptables firewall rules in Linux. It simplifies the process of creating firewall rules, making it easier to protect your system. This tutorial will guide you through the steps to block specific IP addresses using ufw.
1. Installing ufw
If ufw is not already installed on your system, you can install it using your distribution’s package manager:
- For Ubuntu:
sudo apt update sudo apt install ufw
- For CentOS:
sudo yum install ufw
2. Enabling ufw
Before you can use ufw to block IPs, you need to enable it. Run the following command:
sudo ufw enable
You will receive a confirmation that ufw is active.
3. Checking the Status
To check the status of ufw and view the current rules, use:
sudo ufw status verbose
This displays detailed information about active rules and their current state.
4. Blocking an IP Address
To block a specific IP address, use the following command:
sudo ufw deny from
For example, to block the IP address 192.168.1.100
, run:
sudo ufw deny from 192.168.1.100
This command will prevent any incoming connections from the specified IP.
5. Allowing an IP Address
If you ever need to allow a previously blocked IP address, use:
sudo ufw allow from
For example:
sudo ufw allow from 192.168.1.100
6. Viewing the Blocked IPs
To see which IP addresses have been blocked, you can check the status again:
sudo ufw status
This will show you a list of allowed and denied IPs.
7. Conclusion
By following this tutorial, you have learned how to effectively block and manage IP addresses using ufw on your Linux system. Using firewall rules helps secure your server against unwanted traffic and potential attacks. Continue to explore other ufw features to enhance your system’s security!