簡體   English   中英

iptables防止洪水泛濫

[英]Iptables Prevent Flooding

我知道您可以限制每個ip,每個時間間隔等的連接數,但是我想要的是數據量。

我正在托管一個套接字服務器,我想與其進行處理以檢查是否泛洪,而不是將其卸載到防火牆。 我知道您可以防范Syn Flood攻擊,如下所示:

http://www.cyberciti.biz/tips/howto-limit-linux-syn-attacks.html

例如:

# Limit the number of incoming tcp connections
# Interface 0 incoming syn-flood protection
iptables -N syn_flood
iptables -A INPUT -p tcp --syn -j syn_flood
iptables -A syn_flood -m limit --limit 1/s --limit-burst 3 -j RETURN
iptables -A syn_flood -j DROP
#Limiting the incoming icmp ping request:
iptables -A INPUT -p icmp -m limit --limit  1/s --limit-burst 1 -j ACCEPT
iptables -A INPUT -p icmp -m limit --limit 1/s --limit-burst 1 -j LOG --log-prefix PING-DROP:
iptables -A INPUT -p icmp -j DROP
iptables -A OUTPUT -p icmp -j ACCEPT

我不確定iptables可以做什么,所以這個問題有點含糊。 但是由於Web套接字使用tcp,所以我應該能夠限制每秒的字節數。 並標記超出該限制的連接,或者只是丟棄它們,無論如何。

我似乎在這方面找不到很好的參考,因為它們全都關於跟蹤連接等,而不是數據傳輸。 有誰知道一個很好的參考書或如何做到這一點? iptables不是一個好的防火牆嗎? 如果不是,那是什么?

內核側防火牆是最快,最安全的軟件解決方案(不是很難殺死內核嗎?) 使用它還具有使用某些網絡控制器上的硬件防火牆的優勢。 iptables是控制它的主要工具,但是還有許多其他的語法更簡單的前端

如果您想簡化配置,則應使用以下命令: 流量整形配置的屏幕截圖
請記住,跟蹤每個IP的字節數會占用大量內存。
在您的情況下,我將安裝ipset ,它是由同一組iptables開發的:

#create ipset for accounting with default lifetime 300 secs
ipset create IP_QUOTA_SET hash:ip timeout 300 counters

#create separated rule chain
iptables --new-chain PER_IP_QOUTING

#send packets to chain
iptables -t filter -A INPUT \
  -i <in-iface> --dst <ip>  \
  -p tcp --dport <dstport>  \
  -j PER_IP_QUOTING

#if ip doesn't exist in the set, add it
iptables -t filter -A PER_IP_QUOTING    \
  -m set ! --match-set IP_QUOTA_SET src \
  -j SET --add-set IP_QUOTA_SET src --timeout 300

#if packet exists in the set, check bytes
#if byte counter > quota then drop packet
iptables -t filter -A PER_IP_QUOTING    \
  -m set --match-set IP_QUOTA_SET src   \
  --bytes-gr 1000 -j DROP

#pass other packets (for debug purpose)
iptables -t filter -A PER_IP_QUOTING \
  -j RETURN

在這種情況下,您可以檢查列表並通過ipset命令對其進行編輯。
要顯示帶有計數器和超時的當前列表: ipset list IP_QUOTA_SET

注意: iptables是Linux特定的,自linux 2.4起可用。 以前,用戶空間工具中的內核實現確實在2.0和2.2中有所變化。
3.13版本引入了一項新更改 ,它將取代ipset; arptables; ebtables; ip6tables和iptables用一個工具。
與以前的版本一樣,它們將是過渡期,其中像vuurmuur之類的前端將與內核保持兼容,但不要期望將來使用iptables。

您可以將iptable命令標記與tc(流量整形)一起嘗試: http : //www.amiryan.org/2009/02/16/traffic-shaping-under-linux-with-tc-and-iptables/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM