linux中Iptables限制同一IP串連數防CC/DDOS攻擊方法

來源:互聯網
上載者:User

本文章來給大家介紹linux中Iptables限制同一IP串連數防CC/DDOS攻擊方法,這個只是最基於的防止方法,如果真正的攻擊我們還是需要硬體耿防止哦。

1.限制與80連接埠串連的IP最大串連數為10,可自訂修改。

 代碼如下 複製代碼

iptables -I INPUT -p tcp --dport 80 -m connlimit --connlimit-above 10 -j DROP


2.使用recent模組限制同IP時間內新請求串連數,recent更多功能請參考:Iptables模組recent應用。

 代碼如下 複製代碼

iptables -A INPUT -p tcp --dport 80 --syn -m recent --name webpool --rcheck --seconds 60 --hitcount 10 -j LOG --log-prefix 'DDOS:' --log-ip-options
#60秒10個新串連,超過記錄日誌。
iptables -A INPUT -p tcp --dport 80 --syn -m recent --name webpool --rcheck --seconds 60 --hitcount 10 -j DROP
#60秒10個新串連,超過丟棄資料包。
iptables -A INPUT -p tcp --dport 80 --syn -m recent --name webpool --set -j ACCEPT
#範圍內允許通過。


上面的相對比較簡單,下面我來分析更具體的配置方法。CentOS/Redhat/Fedora

在伺服器執行

 代碼如下 複製代碼
vi /etc/sysconfig/iptables
刪除原來的內容輸入如下內容 儲存
# Generated by iptables-save v1.3.5 on Sun Dec 12 23:55:59 2010
*filter
:INPUT DROP [385263:27864079]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [4367656:3514692346]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -s 127.0.0.1 -j ACCEPT
-A INPUT -p tcp -m tcp –dport 80 -m state –state NEW -m recent –set –name WEB –rsource
-A INPUT -p tcp -m tcp –dport 80 -m state –state NEW -m recent –update –seconds 5 –hitcount 20 –rttl –name WEB –rsource -j DROP
-A INPUT -p tcp -m multiport –ports 21,22,80 -j ACCEPT
-A INPUT -p tcp -m tcp –tcp-flags SYN,RST,ACK SYN -m ttl –ttl-eq 117 -j DROP
-A INPUT -p tcp -m tcp –tcp-flags SYN,RST,ACK SYN -m length –length 0:40 -j DROP
-A INPUT -p tcp -m tcp ! –tcp-flags SYN,RST,ACK SYN -m state –state NEW -j DROP
COMMIT
# Completed on Sun Dec 12 23:55:59 2010

說明此設定僅對外開放21(FTP),22(SSH),80(http網站)三個TCP連接埠。設定80連接埠5秒內20個串連

重啟iptables服務 /etc/init.d/iptables restart
設定iptables隨機啟動chkconfig iptables on

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.