{"id":135,"date":"2023-05-24T15:18:39","date_gmt":"2023-05-24T22:18:39","guid":{"rendered":"https:\/\/www.cmsws.com\/blog\/?p=135"},"modified":"2023-05-27T05:52:41","modified_gmt":"2023-05-27T12:52:41","slug":"use-ipset-with-iptables-to-block-inbound-traffic","status":"publish","type":"post","link":"https:\/\/www.cmsws.com\/blog\/use-ipset-with-iptables-to-block-inbound-traffic\/","title":{"rendered":"Use ipset with iptables to block inbound traffic"},"content":{"rendered":"\n<p>I find myself in need of automating the blocking of IPs that I find in mail and auth logs.  The system it old enough I cannot install fail2ban.  I figured out a way to make it happen with iptables and ipset instead.  Read along as I provide the details about blocking inbound traffic using a list dynamically generate with ipset and read in by iptables.<\/p>\n\n\n\n<p>I could suggest a way to feed <code>iptables<\/code> with list of <code>IPs<\/code> by using <code>ipset<\/code>.<\/p>\n\n\n\n<p>you can simply create and <code>ipset<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ipset create &lt;ipset name&gt; iphash<\/code><\/pre>\n\n\n\n<p>then you can add any <code>IP<\/code> to the set using:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ipset add &lt;ipset name&gt; IP<\/code><\/pre>\n\n\n\n<p>after that you can use the set in <code>iptables<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/sbin\/iptables --append INPUT -m set --match-set &lt;ipset name&gt; src -j DROP<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I find myself in need of automating the blocking of IPs that I find in mail and auth logs. The system it old enough I cannot install fail2ban. I figured out a way to make it happen with iptables and ipset instead. Read along as I provide the details about blocking inbound traffic using a list dynamically generate with ipset [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-135","post","type-post","status-publish","format-standard","hentry","category-linux"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/posts\/135","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/comments?post=135"}],"version-history":[{"count":2,"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/posts\/135\/revisions"}],"predecessor-version":[{"id":164,"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/posts\/135\/revisions\/164"}],"wp:attachment":[{"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/media?parent=135"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/categories?post=135"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cmsws.com\/blog\/wp-json\/wp\/v2\/tags?post=135"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}