Adding iptables rules after implementing fail2ban

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















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?










share|improve this question
























  • 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 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?










share|improve this question
























  • 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












0








0


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?










share|improve this question
















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?







linux iptables firewall fail2ban






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 9 '16 at 0:01







Mike Dank

















asked Dec 7 '16 at 22:10









Mike DankMike Dank

11




11












  • 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


















  • 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

















The question is not so clear. Probably the title is wrong.

– Giacomo Catenazzi
Dec 8 '16 at 11:35





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





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






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











1 Answer
1






active

oldest

votes


















0














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






share|improve this answer























  • 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








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f328802%2fadding-iptables-rules-after-implementing-fail2ban%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














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






share|improve this answer























  • 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















0














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






share|improve this answer























  • 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













0












0








0







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






share|improve this answer













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







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 8 '16 at 11:40









Giacomo CatenazziGiacomo Catenazzi

2,063515




2,063515












  • 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

















  • 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
















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






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: 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





@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

















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f328802%2fadding-iptables-rules-after-implementing-fail2ban%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?