{"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":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"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\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Jim Lucas\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.cmsws.com\/blog\/use-ipset-with-iptables-to-block-inbound-traffic\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"A different perspective \u203a Right, lets get on with it...\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Use ipset with iptables to block inbound traffic \u203a A different perspective\" \/>\n\t\t<meta property=\"og:description\" content=\"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\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.cmsws.com\/blog\/use-ipset-with-iptables-to-block-inbound-traffic\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2023-05-24T22:18:39+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2023-05-27T12:52:41+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Use ipset with iptables to block inbound traffic \u203a A different perspective\" \/>\n\t\t<meta name=\"twitter:description\" content=\"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\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"BlogPosting\",\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/use-ipset-with-iptables-to-block-inbound-traffic\\\/#blogposting\",\"name\":\"Use ipset with iptables to block inbound traffic \\u203a A different perspective\",\"headline\":\"Use ipset with iptables to block inbound traffic\",\"author\":{\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/author\\\/jlucas\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/#organization\"},\"datePublished\":\"2023-05-24T15:18:39-07:00\",\"dateModified\":\"2023-05-27T05:52:41-07:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/use-ipset-with-iptables-to-block-inbound-traffic\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/use-ipset-with-iptables-to-block-inbound-traffic\\\/#webpage\"},\"articleSection\":\"Linux\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/use-ipset-with-iptables-to-block-inbound-traffic\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.cmsws.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/category\\\/linux\\\/#listItem\",\"name\":\"Linux\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/category\\\/linux\\\/#listItem\",\"position\":2,\"name\":\"Linux\",\"item\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/category\\\/linux\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/use-ipset-with-iptables-to-block-inbound-traffic\\\/#listItem\",\"name\":\"Use ipset with iptables to block inbound traffic\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/use-ipset-with-iptables-to-block-inbound-traffic\\\/#listItem\",\"position\":3,\"name\":\"Use ipset with iptables to block inbound traffic\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/category\\\/linux\\\/#listItem\",\"name\":\"Linux\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/#organization\",\"name\":\"A different perspective\",\"description\":\"Right, lets get on with it...\",\"url\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/\",\"telephone\":\"+15414085189\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/author\\\/jlucas\\\/#author\",\"url\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/author\\\/jlucas\\\/\",\"name\":\"Jim Lucas\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/use-ipset-with-iptables-to-block-inbound-traffic\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3cbbbf6cb05c36455e4560d55d14ec27e194a9639eef5b88d16f0d547e8c55c7?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Jim Lucas\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/use-ipset-with-iptables-to-block-inbound-traffic\\\/#webpage\",\"url\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/use-ipset-with-iptables-to-block-inbound-traffic\\\/\",\"name\":\"Use ipset with iptables to block inbound traffic \\u203a A different perspective\",\"description\":\"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\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/use-ipset-with-iptables-to-block-inbound-traffic\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/author\\\/jlucas\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/author\\\/jlucas\\\/#author\"},\"datePublished\":\"2023-05-24T15:18:39-07:00\",\"dateModified\":\"2023-05-27T05:52:41-07:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/\",\"name\":\"A different perspective\",\"description\":\"Right, lets get on with it...\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.cmsws.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Use ipset with iptables to block inbound traffic \u203a A different perspective","description":"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","canonical_url":"https:\/\/www.cmsws.com\/blog\/use-ipset-with-iptables-to-block-inbound-traffic\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"BlogPosting","@id":"https:\/\/www.cmsws.com\/blog\/use-ipset-with-iptables-to-block-inbound-traffic\/#blogposting","name":"Use ipset with iptables to block inbound traffic \u203a A different perspective","headline":"Use ipset with iptables to block inbound traffic","author":{"@id":"https:\/\/www.cmsws.com\/blog\/author\/jlucas\/#author"},"publisher":{"@id":"https:\/\/www.cmsws.com\/blog\/#organization"},"datePublished":"2023-05-24T15:18:39-07:00","dateModified":"2023-05-27T05:52:41-07:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.cmsws.com\/blog\/use-ipset-with-iptables-to-block-inbound-traffic\/#webpage"},"isPartOf":{"@id":"https:\/\/www.cmsws.com\/blog\/use-ipset-with-iptables-to-block-inbound-traffic\/#webpage"},"articleSection":"Linux"},{"@type":"BreadcrumbList","@id":"https:\/\/www.cmsws.com\/blog\/use-ipset-with-iptables-to-block-inbound-traffic\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.cmsws.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.cmsws.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.cmsws.com\/blog\/category\/linux\/#listItem","name":"Linux"}},{"@type":"ListItem","@id":"https:\/\/www.cmsws.com\/blog\/category\/linux\/#listItem","position":2,"name":"Linux","item":"https:\/\/www.cmsws.com\/blog\/category\/linux\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.cmsws.com\/blog\/use-ipset-with-iptables-to-block-inbound-traffic\/#listItem","name":"Use ipset with iptables to block inbound traffic"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.cmsws.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.cmsws.com\/blog\/use-ipset-with-iptables-to-block-inbound-traffic\/#listItem","position":3,"name":"Use ipset with iptables to block inbound traffic","previousItem":{"@type":"ListItem","@id":"https:\/\/www.cmsws.com\/blog\/category\/linux\/#listItem","name":"Linux"}}]},{"@type":"Organization","@id":"https:\/\/www.cmsws.com\/blog\/#organization","name":"A different perspective","description":"Right, lets get on with it...","url":"https:\/\/www.cmsws.com\/blog\/","telephone":"+15414085189"},{"@type":"Person","@id":"https:\/\/www.cmsws.com\/blog\/author\/jlucas\/#author","url":"https:\/\/www.cmsws.com\/blog\/author\/jlucas\/","name":"Jim Lucas","image":{"@type":"ImageObject","@id":"https:\/\/www.cmsws.com\/blog\/use-ipset-with-iptables-to-block-inbound-traffic\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/3cbbbf6cb05c36455e4560d55d14ec27e194a9639eef5b88d16f0d547e8c55c7?s=96&d=mm&r=g","width":96,"height":96,"caption":"Jim Lucas"}},{"@type":"WebPage","@id":"https:\/\/www.cmsws.com\/blog\/use-ipset-with-iptables-to-block-inbound-traffic\/#webpage","url":"https:\/\/www.cmsws.com\/blog\/use-ipset-with-iptables-to-block-inbound-traffic\/","name":"Use ipset with iptables to block inbound traffic \u203a A different perspective","description":"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","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.cmsws.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.cmsws.com\/blog\/use-ipset-with-iptables-to-block-inbound-traffic\/#breadcrumblist"},"author":{"@id":"https:\/\/www.cmsws.com\/blog\/author\/jlucas\/#author"},"creator":{"@id":"https:\/\/www.cmsws.com\/blog\/author\/jlucas\/#author"},"datePublished":"2023-05-24T15:18:39-07:00","dateModified":"2023-05-27T05:52:41-07:00"},{"@type":"WebSite","@id":"https:\/\/www.cmsws.com\/blog\/#website","url":"https:\/\/www.cmsws.com\/blog\/","name":"A different perspective","description":"Right, lets get on with it...","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.cmsws.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"A different perspective \u203a Right, lets get on with it...","og:type":"article","og:title":"Use ipset with iptables to block inbound traffic \u203a A different perspective","og:description":"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","og:url":"https:\/\/www.cmsws.com\/blog\/use-ipset-with-iptables-to-block-inbound-traffic\/","article:published_time":"2023-05-24T22:18:39+00:00","article:modified_time":"2023-05-27T12:52:41+00:00","twitter:card":"summary_large_image","twitter:title":"Use ipset with iptables to block inbound traffic \u203a A different perspective","twitter:description":"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"},"aioseo_meta_data":{"post_id":"135","title":null,"description":null,"keywords":[],"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"BlogPosting","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"breadcrumb_settings":null,"limit_modified_date":true,"ai":null,"created":"2023-05-26 01:47:27","updated":"2025-07-23 02:31:38","seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.cmsws.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.cmsws.com\/blog\/category\/linux\/\" title=\"Linux\">Linux<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tUse ipset with iptables to block inbound traffic\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.cmsws.com\/blog"},{"label":"Linux","link":"https:\/\/www.cmsws.com\/blog\/category\/linux\/"},{"label":"Use ipset with iptables to block inbound traffic","link":"https:\/\/www.cmsws.com\/blog\/use-ipset-with-iptables-to-block-inbound-traffic\/"}],"_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}]}}