This project provides lists of datacenter IP addresses and scripts to help you block them using ufw or iptables. By blocking these IPs, you can reduce the amount of bot traffic to your servers.
It gets ASNs of hosting providers from O-X-L/risk-db-lists and generates the subnet lists from that.
I have excluded the following ASNs from the above list. See notSoBadASNs in index.ts
- Cloudflare (13335)
A GitHub workflow automatically updates the IP lists in this repo every 6 hours. You can directly download those if you need them for some other purpose like risk scores...
Modifying firewall rules can be dangerous and may lock you out of your server if not done carefully. Before using these scripts, please ensure you have:
- Backup access to your server: This could be through a cloud provider's web console or physical access.
- Whitelisted your own IP address: Make sure your current IP address is allowed by your firewall rules to prevent losing access. You can add a rule like
sudo ufw allow from YOUR_IP_ADDRESS to anyto allow your own IP.
Use these scripts at your own risk.
You must have Bun installed on your system to generate the firewall scripts.
-
Clone the Repository
git clone https://github.com/brahma-dev/ufw-bots.git cd ufw-bots -
Install Dependencies
bun install
-
Generate the lists
bun start
This command will generate
ipv4.txt,ipv6.txtandcombined.txtin thefilesdirectory. -
Run the Script
You can inspect the scripts. When you are ready, run the appropriate script for your firewall:
-
For UFW:
sudo ./files/ufw.sh
-
For IPTables:
(Requires
ipsetto be installed)sudo ./files/iptables.sh
-
To keep your blocklist updated automatically, you can set up a cron job. The safest way to run scheduled tasks that require root permissions is to add them to the root user's crontab.
-
Open the root user's crontab editor.
sudo crontab -e
-
Add one of the following lines to the file. This will run the update script every 6 hours. Make sure to replace
/path/to/ufw-botswith the actual path to where you cloned the repository. Replacebunwith it's full path if it's not in root's $PATH-
For UFW:
0 */6 * * * cd /path/to/ufw-bots && bun install && bun start && ./files/ufw.sh
0 */6 * * * cd /home/username/ufw-bots && /home/username/.bun/bin/bun install && /home/username/.bun/bin/bun start && ./files/ufw.sh
-
For IPTables:
0 */6 * * * cd /path/to/ufw-bots && bun install && bun start && ./files/iptables.sh
0 */6 * * * cd /home/username/ufw-bots && /home/username/.bun/bin/bun install && /home/username/.bun/bin/bun start && ./files/iptables.sh
-
-
Save and exit the editor. The cron job is now active.
If you need to remove the firewall rules added by this script, follow these instructions.
cd /path/to/ufw-bots
sudo ./files/ufw_remove.shcd /path/to/ufw-bots
sudo ./files/iptables_remove.shShell expert to vet / improve the scripts.