This script will block the specific countries you've asked of it to block.
#!/bin/sh
#Block specific countries from hitting your server (CentOS)
#Install ipset if you dont have it
yum install ipset -y
#!/bin/sh
#Block specific countries from hitting your server (CentOS)
#Install ipset if you dont have it
yum install ipset -y
#Countries to block
#china, france, germany, russian federation, united arab emirates
#china, france, germany, russian federation, united arab emirates
#Create the initial rules in ipset based on hast:net
for a in {china,france,germany,russia,uae,canada,australia}; do ipset -N $a hash:net; done
for a in {china,france,germany,russia,uae,canada,australia}; do ipset -N $a hash:net; done
#Download the necessary files from ipdeny
wget -P . http://www.ipdeny.com/ipblocks/data/countries/cn.zone
wget -P . http://www.ipdeny.com/ipblocks/data/countries/fr.zone
wget -P . http://www.ipdeny.com/ipblocks/data/countries/de.zone
wget -P . http://www.ipdeny.com/ipblocks/data/countries/ru.zone
wget -P . http://www.ipdeny.com/ipblocks/data/countries/ae.zone
wget -P . http://www.ipdeny.com/ipblocks/data/countries/ca.zone
wget -P . http://www.ipdeny.com/ipblocks/data/countries/au.zone
#Add each IP address from the downloaded list into the ipset you've created
for a in $(cat /root/cn.zone ); do ipset -A china $a; done
for b in $(cat /root/fr.zone ); do ipset -A france $b; done
for c in $(cat /root/de.zone ); do ipset -A germany $c; done
for d in $(cat /root/ru.zone ); do ipset -A russia $d; done
for e in $(cat /root/ae.zone ); do ipset -A uae $e; done
for f in $(cat /root/ca.zone ); do ipset -A canada $f; done
for g in $(cat /root/au.zone ); do ipset -A australia $g; done
for a in $(cat /root/cn.zone ); do ipset -A china $a; done
for b in $(cat /root/fr.zone ); do ipset -A france $b; done
for c in $(cat /root/de.zone ); do ipset -A germany $c; done
for d in $(cat /root/ru.zone ); do ipset -A russia $d; done
for e in $(cat /root/ae.zone ); do ipset -A uae $e; done
for f in $(cat /root/ca.zone ); do ipset -A canada $f; done
for g in $(cat /root/au.zone ); do ipset -A australia $g; done
#Backup the iptables
/sbin/iptables-save > /root/iptables.$(date '+%Y%m%d')
/sbin/iptables-save > /root/iptables.$(date '+%Y%m%d')
#Add the following loop statement into your iptables to block the countries you want
for a in {china,france,germany,russia,uae,canada,australia}; do iptables -I INPUT -p tcp -m set --match-set $a src -j DROP; done
for a in {china,france,germany,russia,uae,canada,australia}; do iptables -I INPUT -p tcp -m set --match-set $a src -j DROP; done
#Save the current configuration for iptables
service iptables save
UN AUTRE SCRIPT
https://tecadmin.net/allow-server-access-based-on-country/
Commentaires
Enregistrer un commentaire