PC & IT SUPPORT MADE EASY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Block China IPs Using Linux

Go down

Block China IPs Using Linux Empty Block China IPs Using Linux

Post by jamied_uk 7th April 2021, 16:26

Code:
sudo apt install -y ipset xed gedit
Next, I wrote a small Bash script to do all the work, which you should be able to understand from the comments in it. Create a file:
Code:
xed /etc/block-china.sh
Here's what you want to paste into it:
Code:
# Create the ipset list
ipset -N china hash:net

# remove any old list that might exist from previous runs of this script
rm cn.zone

# Pull the latest IP set for China
wget -P . http://www.ipdeny.com/ipblocks/data/countries/cn.zone

# Add each IP address from the downloaded list into the ipset 'china'
for i in $(cat /etc/cn.zone ); do ipset -A china $i; done

# Restore iptables
/sbin/iptables-restore < /etc/iptables.firewall.rules
jamied_uk
jamied_uk
Admin

Posts : 2951
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum