別の IP にルーティングするための fail2ban アクション

別の IP にルーティングするための fail2ban アクション

禁止アクションでトラフィックを別の 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-client の再起動

/etc/fail2ban の下にある 'action.d/iptables-route.conf' にアクセス可能な設定ファイルが見つかりません

アクション 'iptables-route.conf' を読み取れません

jail '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 転送 -i ens3 -p tcp -m 状態 --state NEW --dport 80 -j 受け入れ

-A 転送 -i ens3 -p tcp -m 状態 --state NEW --dport 443 -j 受け入れ

そこで、ロード/アンロード時にそれらを追加したり削除したりする独自のアクションを作成することにしました。

ポストルーティングも実装する必要があることを忘れていましたが、これを実現するにはさらに再考する必要があります。

私が欲しいもの:

禁止措置では、リクエストは単に拒否/ドロップするのではなく、「無効なリクエストが多すぎるため禁止されています」というページがホストされている別の IP にルーティングされます。

関連情報