Berikut ini kami berikan panduan agar server Anda hanya dapat diakses dari Indonesia. Silakan ketik perintah berikut:
vi allow-indonesia.sh
Lalu masukan script berikut pada file allow-indonesia.sh seperti berikut :
#!/bin/sh
#Allow specific countries from hitting your server (CentOS)
#Install ipset if you dont have it
yum install ipset -y
#Country to allow
#indonesia
#Create the initial rules in ipset based on hast:net
for a in indonesia; do ipset -N $a hash:net; done
#Download the necessary files from ipdeny
wget -P . http://www.ipdeny.com/ipblocks/data/countries/id.zone
#Add each IP address from the downloaded list into the ipset you've created
for a in $(cat /root/id.zone ); do ipset -A indonesia $a; done
#Backup the iptables
/sbin/iptables-save > /root/iptables.$(date '+%Y%m%d')
#Add the following loop statement into your iptables to allow the countries you want
for a in indonesia; do iptables -I INPUT -p tcp -m set --match-set $a src -j ACCEPT; done
for a in indonesia; do iptables -I INPUT -p udp -m set --match-set $a src -j ACCEPT; done
for a in indonesia; do iptables -I INPUT -p icmp -m set --match-set $a src -j ACCEPT; done
#drop all except indo
iptables -A INPUT -i eth1 -j DROP
#Save the current configuration for iptables
service iptables save
#remove zone
rm -rf /root/*.zone*
Selanjutnya, ketik perintah untuk membuat file script update-allow-indonesia.sh
vi update-allow-indonesia.sh
Lalu, masukkan script berikut pada file update-allow-indonesia.sh
#!/bin/sh
#allow specific countries from hitting your server (CentOS)
#Create the initial rules in ipset based on hast:net
for a in indonesia; do ipset -N $a hash:net; done
#Download the necessary files from ipdeny
wget -P . http://www.ipdeny.com/ipblocks/data/countries/id.zone
#Add each IP address from the downloaded list into the ipset you've created
for a in $(cat /root/id.zone ); do ipset -A indonesia $a; done
#remove zone
rm -rf /root/*.zone*
Jika sudah selesai, selanjutnya Anda ketik perintah berikut
chmod +x allow-indonesia.sh
cd /root/
./allow-indonesia.sh
Jika berhasil, maka akan menampilkan seperti ini
Selanjutnya, masukkan perintah berikut
chmod +x update-allow-indonesia.sh
echo "@monthly /root/update-allow-indonesia.sh" >> /var/spool/cron/root
Panduan tersebut dapat dijalankan menggunakan Sistem Operasi Centos Linux. Panduan Membuka Blokir Akses Internasional VPS
Note : eth1 adalah interface ip public, apabila Anda menggunakan server selain Cloudmatika silahkan disesuaikan