防止服務器被外網的IP地址ssh連接或掃描試探等

代碼內容修改於餘洪春老師的構建高可用Linux服務器第二版

  問題:給朋友的一個安全類腳本,爲了防止被其他IP通過ssh手段連接服務器或受到的騷擾。

  以下是在CentOS release 6.3 x64系統一個外網論壇上測試的結果。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# cat hosts_deny.sh
-----------------------------------------------------------------------
#!/bin/bash
#Host.deny Shell Script
#2013-08-24
cat/var/log/secure| awk'/Failed/{print $(NF-3)}'| sort| uniq-c | awk'{print $2 "=" $1;}'> /tmp/black_ip.txt
DEFINE=10
fori in`cat/tmp/black_ip.txt`
do
IP=`echo$i | awk-F= '{print $1}'`
NUM=`echo$i | awk-F= '{print $2}'`
if[ $NUM -gt $DEFINE ]
then
grep$IP /etc/hosts.deny > /dev/null
if[ $? -gt 0 ]
then
echo"sshd:$IP">> /etc/hosts.deny
fi
fi
done
-----------------------------------------------------------------------# crontab -l
*/1* * * * sh /shell_script/hosts_deny.sh
-----------------------------------------------------------------------# grep sshd /etc/hosts.deny
sshd:116.10.202.163
sshd:116.10.202.169
sshd:118.26.203.66
sshd:119.80.39.55
sshd:202.203.194.45
sshd:219.148.36.20
sshd:60.190.219.98
sshd:61.155.177.58
sshd:67.205.111.20
sshd:70.34.202.31
sshd:77.65.0.86

以上IP就是通過腳本查到的,建議大家使用,也希望大家多支持餘洪春老師作品。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章