<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.solace.net/index.php?action=history&amp;feed=atom&amp;title=GeoIP_restriction_in_Linux_with_xtables</id>
	<title>GeoIP restriction in Linux with xtables - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.solace.net/index.php?action=history&amp;feed=atom&amp;title=GeoIP_restriction_in_Linux_with_xtables"/>
	<link rel="alternate" type="text/html" href="https://wiki.solace.net/index.php?title=GeoIP_restriction_in_Linux_with_xtables&amp;action=history"/>
	<updated>2026-10-22T20:54:59Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.10</generator>
	<entry>
		<id>https://wiki.solace.net/index.php?title=GeoIP_restriction_in_Linux_with_xtables&amp;diff=55&amp;oldid=prev</id>
		<title>Kc at 19:50, 25 January 2025</title>
		<link rel="alternate" type="text/html" href="https://wiki.solace.net/index.php?title=GeoIP_restriction_in_Linux_with_xtables&amp;diff=55&amp;oldid=prev"/>
		<updated>2025-01-25T19:50:22Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 12:50, 25 January 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l8&quot;&gt;Line 8:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 8:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;That said, here&#039;s an amended, easier way to do GeoIP IPv4 with Debian:&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;That said, here&#039;s an amended, easier way to do GeoIP IPv4 with Debian &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;(12.x as of this writing)&lt;/ins&gt;:&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Basic steps ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Basic steps ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Kc</name></author>
	</entry>
	<entry>
		<id>https://wiki.solace.net/index.php?title=GeoIP_restriction_in_Linux_with_xtables&amp;diff=54&amp;oldid=prev</id>
		<title>Kc: Created page with &quot;&#039;&#039;&lt;big&gt;Original blog post: https://www.phreakmonkey.com/2022/01/howto-geoip-restrictions-for-amazon.html&lt;/big&gt;&#039;&#039;  == Background == I originally wrote about the process (above) for doing IPv4 GeoIP restriction to a host / service using [https://xtables-addons.sourceforge.net/ xtables-addons] and [https://www.maxmind.com/en/geoip-databases Maxmind&#039;s GeoIP database] with Amazon Linux 2.  This approach worked but had the huge drawback of needing to update, compile, and insta...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.solace.net/index.php?title=GeoIP_restriction_in_Linux_with_xtables&amp;diff=54&amp;oldid=prev"/>
		<updated>2025-01-25T19:49:51Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;#039;&amp;#039;&amp;lt;big&amp;gt;Original blog post: https://www.phreakmonkey.com/2022/01/howto-geoip-restrictions-for-amazon.html&amp;lt;/big&amp;gt;&amp;#039;&amp;#039;  == Background == I originally wrote about the process (above) for doing IPv4 GeoIP restriction to a host / service using [https://xtables-addons.sourceforge.net/ xtables-addons] and [https://www.maxmind.com/en/geoip-databases Maxmind&amp;#039;s GeoIP database] with Amazon Linux 2.  This approach worked but had the huge drawback of needing to update, compile, and insta...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;lt;big&amp;gt;Original blog post: https://www.phreakmonkey.com/2022/01/howto-geoip-restrictions-for-amazon.html&amp;lt;/big&amp;gt;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
I originally wrote about the process (above) for doing IPv4 GeoIP restriction to a host / service using [https://xtables-addons.sourceforge.net/ xtables-addons] and [https://www.maxmind.com/en/geoip-databases Maxmind&amp;#039;s GeoIP database] with Amazon Linux 2.  This approach worked but had the huge drawback of needing to update, compile, and install xtables-addons manually &amp;#039;&amp;#039;every time there was a kernel update&amp;#039;&amp;#039;, which was easy to overlook - thereby leaving you suddenly with no GeoIP restrictions.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Whether GeoIP restrictions are worth it at all is a subject of debate.  By and large I&amp;#039;ve abandoned the approach, as they&amp;#039;re super easy to circumvent for a dedicated attacker anyway, and how much value to you really get by limiting opportunistic attackers via geofencing?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
That said, here&amp;#039;s an amended, easier way to do GeoIP IPv4 with Debian:&lt;br /&gt;
&lt;br /&gt;
== Basic steps ==&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;code&amp;gt;apt get xtables-addons-common&amp;lt;/code&amp;gt;&lt;br /&gt;
* &amp;lt;code&amp;gt;apt get cpan&amp;lt;/code&amp;gt; &lt;br /&gt;
** &amp;lt;code&amp;gt;cpan install&amp;lt;/code&amp;gt;&lt;br /&gt;
** &amp;lt;code&amp;gt;cpan Text::CSV Text::CSV_XS Net::CIDR::Lite&amp;lt;/code&amp;gt;&lt;br /&gt;
* Download a &amp;lt;code&amp;gt;Maxmind GeoLite2-Country-CSV&amp;lt;/code&amp;gt; database and extract it&lt;br /&gt;
* &amp;lt;code&amp;gt;mkdir /usr/share/xt_geoip&amp;lt;/code&amp;gt;&lt;br /&gt;
* from the extracted GeoLite2 database directory, run &amp;lt;code&amp;gt;/usr/libexec/xtables-addons/xt_geoip_build_maxmind -s&amp;lt;/code&amp;gt; to install the database where the kernel module can find it.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If all goes well, now you&amp;#039;re all set-up.  You can now use the &amp;lt;code&amp;gt;-m geoip&amp;lt;/code&amp;gt; directive in iptables rules.  E.g.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;# iptables -A INPUT -p tcp --dport 443 -m geoip ! --source-country US -j DROP&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
will drop all TCP port 443 packets that originate from outside the United States.&lt;br /&gt;
&lt;br /&gt;
== Warnings ==&lt;br /&gt;
&lt;br /&gt;
* Localhost (127.0.0.0/8) is outside any known geography.  Allow it before your GeoIP blocking rules&lt;br /&gt;
* Some remote services aren&amp;#039;t GeoIP friendly.  &amp;#039;&amp;#039;&amp;#039;LetsEncrypt / Acme Certificate Verficiation&amp;#039;&amp;#039;,&amp;#039;&amp;#039;&amp;#039;&amp;#039;&amp;#039; in particular, will &amp;#039;&amp;#039;fail to provision new certificates if you&amp;#039;re GeoIP restricting port 80 &amp;amp; 443 traffic to just the US.&amp;#039;&amp;#039;  At the time of this writing it will &amp;#039;&amp;#039;renew existing certificates&amp;#039;&amp;#039; with the GeoIP block in place, just not provision new ones.&lt;/div&gt;</summary>
		<author><name>Kc</name></author>
	</entry>
</feed>