CENTOS 7 新增黑名單禁止IP訪問伺服器

2021-09-10 03:57:18 字數 1036 閱讀 3678

entos7用的是firewall 新增單個黑名單只需要把ip新增到 /etc/hosts.deny

格式  sshd:$ip:deny

vim /etc/hosts.deny   新增你要禁止的ip就可以了

sshd:192.168.1.147:deny

這是允許的 /etc/hosts.allow

sshd:19.16.18.1:allow

sshd:19.16.18.2:allow

多次失敗登入即封掉ip,防止暴力破解的指令碼 超過5次的就加到黑名單

1、編輯指令碼 

vim /usr/local/bin/secure_ssh.sh

#! /bin/bash

cat /var/log/secure|awk '/failed/'|sort|uniq -c|awk '' > /usr/local/bin/black.txt

for i in `cat  /usr/local/bin/black.txt`

doip=`echo $i |awk -f= ''`

num=`echo $i|awk -f= ''`

if [ $num -gt 5 ];then

grep $ip /etc/hosts.deny > /dev/null

if [ $? -gt 0 ];then

echo "sshd:$ip:deny" >> /etc/hosts.deny

fifi

done

2、建立記錄登入失敗次數的檔案 

touch /usr/local/bin/black.txt

3、新增定時 5分鐘執行一次   

*/5 * * * *  sh /usr/local/bin/secure_ssh.sh

4、測試 ssh登入147   

ssh 192.168.1.147

5、檢視黑名單列表是否記錄  

cat /usr/local/bin/black.txt

6、檢視黑名單列表看是否新增進去了 

cat /etc/hosts.deny

centos7新增ip黑名單禁止某個ip訪問

centos7用的是firewall 新增單個黑名單只需要把ip新增到 etc hosts.deny 格式 sshd ip deny vim etc hosts.deny 新增你要禁止的ip就可以了 這是允許的 etc hosts.allow sshd 19.16.18.1 allow sshd 1...

centos7新增ip黑名單禁止某個ip訪問

centos7用的是firewall 新增單個黑名單只需要把ip新增到 etc hosts.deny 格式 sshd ip deny vim etc hosts.deny 新增你要禁止的ip就可以了 這是允許的 etc hosts.allow sshd 19.16.18.1 allow sshd 1...

CENTOS 7 新增黑名單禁止IP訪問伺服器

centos7用的是firewall 新增單個黑名單只需要把ip新增到 etc hosts.deny 格式 sshd ip deny vim etc hosts.deny 新增你要禁止的ip就可以了 sshd 192.168.1.147 deny 這是允許的 etc hosts.allow sshd...