ksta

Block RU Chia nodes

Feb 24th, 2022 (edited)
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.89 KB | None | 0 0
  1. # Block incoming connections from Russian IPs to your Chia node using iptables and ipset.
  2. # Adapted from https://mtxserv.com/vps-server/doc/how-to-block-ip-addresses-by-country
  3. # Execute as root or using sudo.
  4.  
  5. # 1. Install ipset:
  6. apt install ipset
  7. # or
  8. yum install ipset
  9.  
  10. # 2. Create a new ipset called "ru".
  11. ipset create ru hash:net,port
  12.  
  13. # 3. Create a file with the following contents, make it executable:
  14. #!/bin/bash
  15.  
  16. COUNTRIES=('ru')
  17.  
  18. ipset flush ru
  19.  
  20. for i in "${COUNTRIES[@]}"; do
  21.     echo "Ban IP of country ${i}"
  22.  
  23.     for IP in $(wget -O - https://www.ipdeny.com/ipblocks/data/countries/${i}.zone)
  24.     do
  25.         ipset add ru $IP,8444
  26.     done
  27. done
  28.  
  29. # 4. Execute the file you have just created to fill the ipset, it should take only a few seconds.
  30.  
  31. # 5. And finally, create an iptables entry to put the new ipset to work.
  32. iptables -I INPUT -m set --match-set ru src -j DROP
  33.  
Add Comment
Please, Sign In to add comment