Fail2ban

從fail2ban更改鏈名稱

  • October 22, 2016

如何更改 fail2ban 創建的鏈的名稱。

root@host:~# iptables -L INPUT -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
fail2ban-dotcom  tcp  --  0.0.0.0/0            0.0.0.0/0            multiport dports 80,443
fail2ban-ssh  tcp  --  0.0.0.0/0            0.0.0.0/0            multiport dports 22,660
fail2ban-dotde  tcp  --  0.0.0.0/0            0.0.0.0/0            multiport dports 80,443
fail2ban-oc  tcp  --  0.0.0.0/0            0.0.0.0/0            multiport dports 80,443
ACCEPT       all  --  0.0.0.0/0            0.0.0.0/0            /* loopback interface */
ACCEPT       all  --  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED

到:

root@host:~# iptables -L INPUT -n
Chain INPUT (policy ACCEPT)
target     prot  opt  source               destination
f2b-dotcom   tcp  --  0.0.0.0/0            0.0.0.0/0            multiport dports 80,443
f2b-ssh      tcp  --  0.0.0.0/0            0.0.0.0/0            multiport dports 22,660
f2b-dotde    tcp  --  0.0.0.0/0            0.0.0.0/0            multiport dports 80,443
f2b-oc       tcp  --  0.0.0.0/0            0.0.0.0/0            multiport dports 80,443
ACCEPT       all  --  0.0.0.0/0            0.0.0.0/0            /* loopback interface */
ACCEPT       all  --  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED

裡面有/yourpath/fail2ban/action.d/一些iptables*.conf文件。一個動作定義了幾個在不同時刻執行的命令。你的電流的一些行的例子action.d/iptables*.conf

[Definition]

actionstart = iptables -N fail2ban-<name>
             iptables -A fail2ban-<name> -j RETURN
             iptables -I <chain> -p <protocol> --dport <port> -j fail2ban-<name>

actionstop = iptables -D <chain> -p <protocol> --dport <port> -j fail2ban-<name>
        iptables -F fail2ban-<name>
        iptables -X fail2ban-<name>

actioncheck = iptables -n -L <chain> | grep -q fail2ban-<name>

您需要按如下方式編輯配置:

[Definition]

actionstart = iptables -N f2b-<name>
             iptables -A f2b-<name> -j RETURN
             iptables -I <chain> -p <protocol> --dport <port> -j f2b-<name>

actionstop = iptables -D <chain> -p <protocol> --dport <port> -j f2b-<name>
        iptables -F f2b-<name>
        iptables -X f2b<name>

actioncheck = iptables -n -L <chain> | grep -q f2b-<name>

最新版本已經有這些更新。

引用自:https://unix.stackexchange.com/questions/318014