{"id":32,"date":"2016-12-10T12:02:24","date_gmt":"2016-12-10T17:02:24","guid":{"rendered":"http:\/\/www.mbcs.ca\/?p=32"},"modified":"2016-12-10T12:02:24","modified_gmt":"2016-12-10T17:02:24","slug":"shorewall-ipsets-fail2ban-and-recidive-jail-v-2","status":"publish","type":"post","link":"https:\/\/www.mbcs.ca\/?p=32","title":{"rendered":"Shorewall, Ipsets, Fail2Ban and Recidive Jail v.2"},"content":{"rendered":"<p>This is my second post on the above subject.\u00a0 I have now started using ipsets to handle blocking of ip addresses at my firewalls.\u00a0 For the purposes of this post, the ipsets will be call F2BLIST for ipv4 and F2BLIST6 for ipv6 address.\u00a0 In the shorewall init file, place the following code:<\/p>\n<p>ipset create F2BLIST hash:ip timeout 300 -exist<\/p>\n<p>This creates an ipset with a default timeout of 300 seconds, and won&#8217;t throw an error if it already exists (if you happen to restart shorewall).<\/p>\n<p>Next add a rule to the shorewall rules file like:<\/p>\n<p>?SECTION ALL<\/p>\n<p>DROP:info net:+F2BLIST all<\/p>\n<p>Next, create a new action file under \/etc\/fail2ban\/action.d\/ called shorewall-ipset.conf<\/p>\n<p>[Definition]<br \/>\nactionstart =<br \/>\nactionstop =<br \/>\nactioncheck =<br \/>\nactionban = ipset add F2BLIST &lt;ip&gt; timeout &lt;bantime&gt; -exist<br \/>\nactionunban =<br \/>\n[Init]<br \/>\nblocktype = logdrop<br \/>\nbantime = 600<\/p>\n<p>The last line sets the default ban time to 600 seconds.\u00a0 Next, create a jail in \/etc\/fail2ban\/jail.local like the following:<\/p>\n<p>[ssh-shorewall]<\/p>\n<p>enabled = true<br \/>\nfilter = sshd<br \/>\naction = shorewall-ipset[bantime=3600]<br \/>\nsendmail-geoip-lines[name=SSH, dest=youremail, sender=anotheremail, logpath=\/var\/log\/messages]<br \/>\nlogpath = \/var\/log\/messages<br \/>\nmaxretry = 3<\/p>\n<p>This jail sets the ban time to 3600 seconds, and uses the default findtime.\u00a0 A recidive jail could look like the following:<\/p>\n<p>[recidive]<\/p>\n<p>enabled = true<br \/>\nfilter = recidive<br \/>\nlogpath = \/var\/log\/fail2ban.log<br \/>\naction = shorewall-ipset[bantime=172800]<br \/>\nsendmail-geoip-lines[name=recidive, logpath=\/var\/log\/fail2ban.log]<br \/>\nfindtime = 172800 ; 2 day<br \/>\nmaxretry = 2<\/p>\n<p>The beauty of the ipsets is that the kernel handles expiring the entry, so you don&#8217;t have to worry about fail2ban expirying an ip that is still supposed to be blocked in the recidive jail.\u00a0 If you issue the following command:<\/p>\n<p>ipset list<\/p>\n<p>it will show the ipset and all the entries in it with the corresponding seconds left for each ip to expire.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is my second post on the above subject.\u00a0 I have now started using ipsets to handle blocking of ip addresses at my firewalls.\u00a0 For the purposes of this post, the ipsets will be call F2BLIST for ipv4 and F2BLIST6 for ipv6 address.\u00a0 In the shorewall init file, place the following code: ipset create F2BLIST &hellip; <a href=\"https:\/\/www.mbcs.ca\/?p=32\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Shorewall, Ipsets, Fail2Ban and Recidive Jail v.2<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-32","post","type-post","status-publish","format-standard","hentry","category-firewallingsecurity"],"_links":{"self":[{"href":"https:\/\/www.mbcs.ca\/index.php?rest_route=\/wp\/v2\/posts\/32","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mbcs.ca\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mbcs.ca\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mbcs.ca\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mbcs.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=32"}],"version-history":[{"count":1,"href":"https:\/\/www.mbcs.ca\/index.php?rest_route=\/wp\/v2\/posts\/32\/revisions"}],"predecessor-version":[{"id":33,"href":"https:\/\/www.mbcs.ca\/index.php?rest_route=\/wp\/v2\/posts\/32\/revisions\/33"}],"wp:attachment":[{"href":"https:\/\/www.mbcs.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=32"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mbcs.ca\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=32"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mbcs.ca\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=32"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}