Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save patrocle/9409ad066084fd5f6d7854429cacea26 to your computer and use it in GitHub Desktop.
Save patrocle/9409ad066084fd5f6d7854429cacea26 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 -ksSL "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