Loading fail2ban rules to iptables using iptables-persistent

I am using iptables-persistent package to reload my iptables on boot. And I have been thinking should I add the fail2ban rules to the loaded config file? Now I am seeing they are duplicated.

This is my firewall config:

*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:fail2ban-ssh - [0:0]

-A INPUT -p tcp -m multiport --dports 22 -j fail2ban-ssh

# Accepts SSH connection
-A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

# HTTP
-A INPUT -p tcp --dport 80 -j ACCEPT

# SSH
-A INPUT -p tcp --dport 22 -j ACCEPT

# MariaDB (private network)
-A INPUT -i eth1 -p tcp -m tcp --dport 3306 -j ACCEPT

# loopback device
-I INPUT 1 -i lo -j ACCEPT

# Allow ping
-A INPUT -p icmp -j ACCEPT

# Drops all remaining traffic
-A INPUT -j DROP

-A fail2ban-ssh -j RETURN

COMMIT

The fail2ban lines are duplicated when I reboot and run iptables -S:

-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-N fail2ban-ssh
-A INPUT -p tcp -m multiport --dports 22 -j fail2ban-ssh
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 22 -j fail2ban-ssh
-A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -j DROP
-A fail2ban-ssh -j RETURN
-A fail2ban-ssh -j RETURN

So should I remove those 2 fail2ban lines from my config?


Don't bother. fail2ban maintains its own state and will recreate its firewall rules when restarted.