Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save paveli/f86b45ce99ce670f6d95653d22f5397e to your computer and use it in GitHub Desktop.
Save paveli/f86b45ce99ce670f6d95653d22f5397e to your computer and use it in GitHub Desktop.
Block Tor Exit Nodes with IPTables
  1. Install ipset:
apt-get install ipset
  1. Create new ipset:
ipset create tor iphash
  1. Read Tor Exit Node List and add to ipset:
curl -sSL "https://check.torproject.org/cgi-bin/TorBulkExitList.py?ip=$(curl icanhazip.com)" | sed '/^#/d' | while read IP; do
  ipset -q -A tor $IP
done

Note: This should run as daily cronjob.

  1. Block ipset with iptables:
iptables -A INPUT -m set --match-set tor src -j DROP

Source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment