将链名称从fail2ban更改为

将链名称从fail2ban更改为

如何更改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

答案1

里面/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>

最新版本已经有这些更新。

相关内容