
금지 조치 시 트래픽을 다른 IP로 라우팅하고 금지 조치 시 경로를 제거하는 Fail2ban 조치를 생성하고 싶습니다.
파일: /etc/fail2ban/action.d/의 iptables-route.conf
# Fail2Ban configuration file
#
#
[INCLUDES]
before = iptables-common.conf
[Definition]
# Option: actionstart
# Notes.: command executed once at the start of Fail2Ban.
# Values: CMD
#
actionstart = <iptables> -N f2b-<name>
<iptables> -A f2b-<name> -j <returntype>
<iptables> -I <chain> -p <protocol> -m multiport --dports <port> -j f2b-<name>
<iptables> -A FORWARD -i ens3 -p tcp -m state --state NEW --dport 80 -j ACCEPT
<iptables> -A FORWARD -i ens3 -p tcp -m state --state NEW --dport 443 -j ACCEPT
# Option: actionstop
# Notes.: command executed once at the end of Fail2Ban
# Values: CMD
#
actionstop = <iptables> -D <chain> -p <protocol> -m multiport --dports <port> -j f2b-<name>
<actionflush>
<iptables> -X f2b-<name>
<iptables> -D FORWARD -i ens3 -p tcp -m state --state NEW --dport 80 -j ACCEPT
<iptables> -D FORWARD -i ens3 -p tcp -m state --state NEW --dport 443 -j ACCEPT
# Option: actioncheck
# Notes.: command executed once before each actionban command
# Values: CMD
#
actioncheck = <iptables> -n -L <chain> | grep -q 'f2b-<name>[ \t]'
# Option: actionban
# Notes.: command executed when banning an IP. Take care that the
# command is executed with Fail2Ban user rights.
# Tags: See jail.conf(5) man page
# Values: CMD
#
actionban = <iptables> -I f2b-<name> 1 PREROUTING -s <ip> -j DNAT --to-destination 188.68.45.124
# Option: actionunban
# Notes.: command executed when unbanning an IP. Take care that the
# command is executed with Fail2Ban user rights.
# Tags: See jail.conf(5) man page
# Values: CMD
#
actionunban = <iptables> -D f2b-<name> -s <ip> -j DNAT --to-destination 188.68.45.124
[Init]
/etc/fail2ban/jail.d/에 있는 apache-route.local 파일:
[apache-route]
enabled = true
filter = apache-probe
port = http,https
banaction = iptables-route.conf
maxretry = 3
findtime = 1500
bantime = 600
logpath = /var/www/*/userdata/logs/*-access.log
다음과 같은 오류가 발생하기 때문에 테스트할 수도 없습니다.
Fail2ban-클라이언트 재시작
/etc/fail2ban에서 'action.d/iptables-route.conf'에 대한 액세스 가능한 구성 파일을 찾을 수 없습니다.
'iptables-route.conf' 작업을 읽을 수 없습니다.
감옥 'apache-route'에 오류가 있습니다. 건너뛰는 중...
작동시키려고 노력하지만 왜 그런 오류가 발생하는지 전혀 모르겠습니다.
답변1
'iptables-route.conf' 작업을 읽을 수 없습니다.
간단히 .conf
작업 이름에서 제거하십시오.
-banaction = iptables-route.conf
+banaction = iptables-route
그런데. 내가 보기엔 당신의 행동이 좀 잘못된 것 같아요. iptables-multiport
지정된(덮어쓰기) chain
및 으로 기본값을 지정하지 않는 이유는 무엇입니까 blocktype
?
무엇을 시도하고 있는지 잘 모르겠지만 다음과 같은 것은 아닙니다.
banaction = iptables-multiport[chain=PREROUTING, blocktype="DNAT --to-destination 188.68.45.124"]
일을 해?
답변2
지정된(덮어쓴) 체인 및 블록 유형을 사용하여 기본 iptables-multiport를 사용하지 않는 이유는 무엇입니까?
iptables-multiport는 출력 체인을 추가하지 않습니다.
-A FORWARD -i ens3 -p tcp -m state --state NEW --dport 80 -j ACCEPT
-A FORWARD -i ens3 -p tcp -m state --state NEW --dport 443 -j ACCEPT
그래서 로드/언로드 시 해당 항목을 추가하고 제거하는 자체 작업을 만들기로 결정했습니다.
포스트라우팅도 구현해야 한다는 사실을 잊어버렸습니다. 하지만 이를 보관하려면 더 깊이 생각해야 합니다.
내가 원하는 것:
금지 시 요청은 단순히 요청을 거부/삭제하는 대신 "유효하지 않은 요청이 너무 많아 금지되었습니다"라는 페이지가 호스팅되는 다른 IP로 라우팅됩니다.