同一IP一個小時內只允許嘗試建立3次SSH串連

來源:互聯網
上載者:User
同一IP一個小時內只允許嘗試建立3次SSH串連@for & ever 2010-3-16

首先,在/proc/net/ipt_recent/*   下建立不在限制行列的IP列表

然後,設定同一IP,一個小時內只允許嘗試建立3次SSH串連:

iptables -A INPUT -p tcp --dport 22 --syn -m recent --rcheck --seconds 3600 --hitcount 3 --rttl --name SSH --rsource -j DROP

 

iptables -A INPUT -p tcp --dport 22 --syn -m recent --set --name SSH --rsource -j ACCEPT

 

iptables -A INPUT -p tcp --dport 22 -j ACCEPT

 

 

注意 rule順序:

先設定  recent 的-j DROP,再設定recent --set -j ACCEPT

 

 

#設定這個 用來解除鎖定

iptables -A INPUT -p tcp --dport 1600 --syn -j LOG --log-prefix "SSH_CONN_UNLOCKED "

 

iptables -A INPUT -p tcp --dport 1600 --syn -m recent --remove --name SSH --rsource -j REJECT --reject-with icmp-host-unreachable

 

使用方法: telnet linux.host 1600

其中 tcp 1600 port 可以改成任意的未使用的 tcp port

 

/proc/net/ipt_recent/* 列表裡,如果沒有設定 –name,則預設為DEFAULT

樣本如下:

#添加某個IP到DEFAULT 

echo xx.xx.xx.xx > /proc/net/ipt_recent/DEFAULT

 

#從DEFAULT移除某個IP  

echo -xx.xx.xx.xx > /proc/net/ipt_recent/DEFAULT

 

#清空 DEFAULT  

echo clear > /proc/net/ipt_recent/DEFAULT

 

 

 

@forandever 2010-3-16

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.