1

I recently implemented fail2ban on a fresh debian server which left me with some default iptables configuration automatically,

root@plutarchy:/etc/apache2# iptables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-N fail2ban-ssh
-A INPUT -p tcp -m multiport --dports 2222 -j fail2ban-ssh
-A fail2ban-ssh -j RETURN

Now, when I add some old iptables rules that I don't want to run through fail2ban, I end up with the following,

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

Note that I need to add the line -A INPUT -p tcp --dport 2222 -j ACCEPT or I cannot ssh into the box.

Will fail2ban still protect ssh (port 2222) when I have this line inserted? If not, how can I make sure ssh still goes through fail2ban while I have port 80 opened for normal operation?

  • The question is not so clear. Probably the title is wrong. – Giacomo Catenazzi Dec 8 '16 at 11:35
  • BTW your iptables rules are confusing. why -m multiport if you specify only one port. -m tcp is not needed. You duplicate conntrack and state. Use only one. (and these are used only for outgoing connections). I really don't like your rules. – Giacomo Catenazzi Dec 8 '16 at 11:44
  • The -m multiport was added automatically by fail2ban (as you can see in my first code block. -m tcp is not an issue per superuser.com/questions/631083/…. I've gone ahead and removed the duplicate behavior between conntrack and state and cleaned up a bit. Everything that you brought up has nothing to do with the question. The question is, will including -A INPUT -p tcp --dport 2222 -j ACCEPT still properly protect ssh (on port 2222) with fail2ban? – Mike Dank Dec 9 '16 at 0:05
0

I think the best way is to modify fail2ban configuration, in order to filter port 2222 instead of 22.

  • fail2ban has been configured to filter port 2222 already. My question is whether or not the port is still protected by fail2ban when I have the line -A INPUT -p tcp --dport 2222 -j ACCEPT in addition to the earlier -A INPUT -p tcp -m multiport --dports 2222 -j fail2ban-ssh – Mike Dank Dec 9 '16 at 0:07
  • @MikeDank: You call fail2ban rule (line 5) before to accept 2222 (line 8), so yes. My comment about bad format of rules was not about the correctness, but the difficult to follow the rules and the logic of rules. There is many things mixing. Note fail2ban ban rules are inserted before the RETURN (last line). – Giacomo Catenazzi Dec 9 '16 at 9:17
  • @MikeDank: In any case, you are doing some security work, so you should test that a host will be banned by fail2ban. Don't trust you (and me). On security, real test is essential.. – Giacomo Catenazzi Dec 9 '16 at 9:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.