|
|
#1 |
|
Senior Member
Join Date: Dec 2011
Posts: 140
|
Hello,
Does anyone know how i can block in my linux server IP's from different country's so they can't get acces to my server ? Thanks in advance
|
|
|
|
|
|
#2 |
|
Administrator
Join Date: Jan 2009
Posts: 1,680
|
you can use iptables to block some ips
do you want to bann all ips from a country? |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Dec 2011
Posts: 140
|
|
|
|
|
|
|
#4 |
|
Administrator
Join Date: Jan 2009
Posts: 1,680
|
Hi
http://ipinfodb.com/ip_country_block.php#blocklist Choose the country for the list , save the file blocklist.txt Upload blocklist.txt on your linux server in a directory create a new file called banip with this content ### SCRIPT ### #!/bin/sh cat blocklist.txt | awk '{print $1;}' | sort | uniq | while read a; do iptables -A INPUT -s $a -j DROP;done sleep 1 /sbin/iptables-save > /etc/sysconfig/iptables chmod go-r /etc/sysconfig/iptables /sbin/service iptables restart upload banip file in the same directory with blocklist.txt , set chmod 755 for banip and then run the banip file I really recomand you to make this job only if you know some minimum linux details, if not you can fault your server |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Dec 2011
Posts: 140
|
Thanks a lot admin, you're the best. Its working, now i don't have a lot of warning.txt in my /tmp folde with "Login Failed..."
Thanks a lot mate. There is 1 thing i want to ask about that script, do i need to run it only 1 time or everyday or once a week or...? Thanks again |
|
|
|
|
|
#6 | |
|
Senior Member
Join Date: Feb 2009
Posts: 306
|
Quote:
Hi Cardsharing, Another question about your banip script file. I have just wanted to use your script as fail2ban code. "Blocklist file" includes only country ip numbers. On the contrary, "log warnings" file includes numeric and alpha-numeric strings. Do you think if that works out as fail2ban code when I make some changes in CCcam.cfg file and below script? In CCcam.cfg file: log warnings: /tmp/warnings.txt In Script: Code:
### SCRIPT ###
#!/bin/sh
cat warnings.txt | awk '{print $1;}' | sort | uniq | while read a; do iptables -A INPUT -s $a -j DROP;done
sleep 1
/sbin/iptables-save > /etc/sysconfig/iptables
chmod go-r /etc/sysconfig/iptables
/sbin/service iptables restart
Thanks in advance Tinkerbell |
|
|
|
|
![]() |
| Tags |
| block, country, ip |
| Thread Tools | |
| Display Modes | |
|
|
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.