<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mathias Stjernstrom</title>
    <description>The latest articles on DEV Community by Mathias Stjernstrom (@stjernstrom).</description>
    <link>https://dev.to/stjernstrom</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F348550%2F0b0be9cb-2e9f-400d-aa13-5a3661dab983.jpeg</url>
      <title>DEV Community: Mathias Stjernstrom</title>
      <link>https://dev.to/stjernstrom</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/stjernstrom"/>
    <language>en</language>
    <item>
      <title>Block IPs on all ports with fail2ban on a docker host</title>
      <dc:creator>Mathias Stjernstrom</dc:creator>
      <pubDate>Thu, 29 Oct 2020 19:41:33 +0000</pubDate>
      <link>https://dev.to/stjernstrom/block-ips-on-all-ports-with-fail2ban-on-a-docker-host-1983</link>
      <guid>https://dev.to/stjernstrom/block-ips-on-all-ports-with-fail2ban-on-a-docker-host-1983</guid>
      <description>&lt;p&gt;Playing around with fail2ban on a local docker host I found that when blocking a host, all docker containers with open ports where still accessible.&lt;/p&gt;

&lt;p&gt;I tried several different ways of getting the IP block to really block everything.&lt;/p&gt;

&lt;p&gt;This is some notes from the steps I took to solve the problem.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Update your package lists
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apt update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Install fail2ban
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apt install fail2ban
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;We do not edit the default jail.conf since it can be overwritten by updates. So we create a new config for fail2ban.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;vim /etc/fail2ban/jail.local
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For this simple demonstration we are going to block all failed attempt over SSH. And we want to block the remote IP for 600s, for all services and ports.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[sshd]
ignoreip = 127.0.0.1
enabled = true
port = 22
filter = sshd
logpath = /var/log/auth.log
maxretry = 3
bantime  = 600
findtime = 600
action = iptables-allports[actname=sshd,name=sshd,protocol=all]
         iptables-allports[actname=sshd-docker,name=sshd-docker,protocol=all,chain=DOCKER]

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The trick was to setup two actions. One for the normal chain/traffic and one for dockers CHAIN.&lt;/p&gt;

&lt;p&gt;Doing this block sessions not only to the host but also all containers. &lt;/p&gt;

</description>
      <category>fail2ban</category>
      <category>docker</category>
      <category>security</category>
      <category>howto</category>
    </item>
  </channel>
</rss>
