
내가 필요한 것 :
랩당 요청량만큼 드롭 규칙을 추가한 결과는 많지만, 일정 시간 동안 특정 주소로부터 수신된 바이트 수만큼 드롭해야 합니다.
내가 조사한 내용 :
iptables를 봤습니다. 첫 번째 경우에는 전용성냥. 나도 봤다할당량 일치그러나 데이터 개수는 전역적으로 추적됩니다.
IP당 수신된 데이터를 추적하기 위해 두 규칙을 혼합하는 방법에 대해서는 전혀 모릅니다.
다른 것들 :
IP당 바이트 수를 추적하면 많은 양의 메모리를 사용할 수 있다는 것을 알고 있으므로 기간을 짧게 유지하고 싶습니다.
자세한 예가 있는 한 다른 방법도 허용됩니다.
답변1
시간 초과 및 카운터 옵션과 함께 IPSET을 사용할 수 있습니다. 이는 다음과 같이 보일 것입니다:
#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_QUOTING
#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 close connection
#by sending of tcp-reset packet.
iptables -t filter -A PER_IP_QUOTING \
-m set --match-set IP_QUOTA_SET src \
--bytes-gt 1000 -j REJECT --reject-with tcp-rst
#pass other packets (for debug purpose)
iptables -t filter -A PER_IP_QUOTING \
-j RETURN
이 경우 ipset 명령으로 목록을 확인하고 편집할 수 있습니다. 카운터 및 시간 초과가 포함된 현재 목록 표시: ipset list IP_QUOTA_SET.
자세한 내용은 설명서를 읽어보세요.