Skip to main content

Firewall

UFW / iptables Blocklist Tutorial

Block VPN, proxy and Tor IPs at the Linux firewall level using UFW or iptables with an ipset loaded from AntiProxies TXT blocklist files.

Supported formats: TXT (one IP/CIDR per line)

Steps

  1. 1

    Install ipset

    ipset allows managing large IP sets efficiently in the kernel. Install it with apt install ipset or yum install ipset.

  2. 2

    Create an ipset

    Create a hash:net ipset named antiproxies that supports both single IPs and CIDR ranges.

  3. 3

    Load the blocklist into ipset

    Download the TXT blocklist and feed each line into ipset add antiproxies <IP>. A script automates this.

  4. 4

    Add iptables / UFW rule

    Add a DROP rule that matches the antiproxies set. This blocks matching traffic at the kernel level before it reaches your application.

  5. 5

    Persist across reboots

    Use ipset save to write the set to disk and ipset restore on boot (e.g. via /etc/rc.local) so rules survive a restart.

Need the blocklist files?

Download free sample data or subscribe for daily-updated lists.

Free Sample

Setup script (one-time)

Create the ipset and iptables rule. Run once on setup.

/usr/local/bin/setup-antiproxies-fw.sh
#!/bin/bash
# One-time setup: create ipset and iptables rule

# Install ipset if missing
which ipset || apt-get install -y ipset

# Create set (hash:net supports CIDRs)
ipset create antiproxies hash:net maxelem 1000000 2>/dev/null || true

# Add DROP rule if not already present
if ! iptables -C INPUT -m set --match-set antiproxies src -j DROP 2>/dev/null; then
    iptables -I INPUT -m set --match-set antiproxies src -j DROP
fi

echo "ipset and iptables rule configured."

Frequently asked questions

Why use ipset instead of individual iptables rules?
iptables evaluates rules linearly – 100,000 individual DROP rules would be extremely slow. ipset uses a hash table in the kernel, so matching 1 million IPs takes the same time as matching 10.
Will this block UDP as well as TCP?
Yes. The iptables INPUT rule matches all protocols by default. Add -p tcp or -p udp to restrict to specific protocols.
How do I unblock an IP temporarily?
Run ipset del antiproxies <IP> to remove a single entry.

Want to see what's in the database?

Download once, query as many times as you need. €99/year for all 22 databases, unlimited servers, and a full year of monthly updates. No usage limits, no per-query fees, no data leaving your servers.

30-day money-back guarantee
All databases included
Monthly updates