<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://wiki.nftables.org/wiki-nftables/index.php?action=history&amp;feed=atom&amp;title=GeoIP_matching</id>
	<title>GeoIP matching - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.nftables.org/wiki-nftables/index.php?action=history&amp;feed=atom&amp;title=GeoIP_matching"/>
	<link rel="alternate" type="text/html" href="http://wiki.nftables.org/wiki-nftables/index.php?title=GeoIP_matching&amp;action=history"/>
	<updated>2026-05-13T18:16:04Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>http://wiki.nftables.org/wiki-nftables/index.php?title=GeoIP_matching&amp;diff=531&amp;oldid=prev</id>
		<title>Jose: Update github clone link</title>
		<link rel="alternate" type="text/html" href="http://wiki.nftables.org/wiki-nftables/index.php?title=GeoIP_matching&amp;diff=531&amp;oldid=prev"/>
		<updated>2020-08-03T10:31:33Z</updated>

		<summary type="html">&lt;p&gt;Update github clone link&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 10:31, 3 August 2020&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-l4&quot;&gt;Line 4:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 4:&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;== How to get the script ==&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;== How to get the script ==&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; 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;Clone [https://github.com/&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;JMGuisadoG&lt;/del&gt;/nftables-geoip nftables-geoip repo]&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;Clone [https://github.com/&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;pvxe&lt;/ins&gt;/nftables-geoip nftables-geoip repo]&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;== How to use the script ==&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;== How to use the script ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wikidb_nftables:diff:1.41:old-490:rev-531:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Jose</name></author>
	</entry>
	<entry>
		<id>http://wiki.nftables.org/wiki-nftables/index.php?title=GeoIP_matching&amp;diff=490&amp;oldid=prev</id>
		<title>Jose: Fix ip6 example</title>
		<link rel="alternate" type="text/html" href="http://wiki.nftables.org/wiki-nftables/index.php?title=GeoIP_matching&amp;diff=490&amp;oldid=prev"/>
		<updated>2020-01-19T13:08:48Z</updated>

		<summary type="html">&lt;p&gt;Fix ip6 example&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 13:08, 19 January 2020&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-l69&quot;&gt;Line 69:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 69:&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;   meta mark set ip saddr map @geoip4&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;   meta mark set ip saddr map @geoip4&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; 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;   meta mark set &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;ip &lt;/del&gt;saddr map @geoip6&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;   meta mark set &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;ip6 &lt;/ins&gt;saddr map @geoip6&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;== Matching packets by its country code ==&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;== Matching packets by its country code ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wikidb_nftables:diff:1.41:old-489:rev-490:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Jose</name></author>
	</entry>
	<entry>
		<id>http://wiki.nftables.org/wiki-nftables/index.php?title=GeoIP_matching&amp;diff=489&amp;oldid=prev</id>
		<title>Jose: Create geoip matching page</title>
		<link rel="alternate" type="text/html" href="http://wiki.nftables.org/wiki-nftables/index.php?title=GeoIP_matching&amp;diff=489&amp;oldid=prev"/>
		<updated>2020-01-19T10:48:36Z</updated>

		<summary type="html">&lt;p&gt;Create geoip matching page&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
You can use a external script &amp;#039;&amp;#039;&amp;#039;nft_geoip.py&amp;#039;&amp;#039;&amp;#039;, at [https://github.com/JMGuisadoG/nftables-geoip nftables-geoip], to generate mappings between countries and marks that can be later included into your ruleset.&lt;br /&gt;
&lt;br /&gt;
== How to get the script ==&lt;br /&gt;
&lt;br /&gt;
Clone [https://github.com/JMGuisadoG/nftables-geoip nftables-geoip repo]&lt;br /&gt;
&lt;br /&gt;
== How to use the script ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;You can use&amp;#039;&amp;#039; &amp;lt;code lang=&amp;quot;bash&amp;quot;&amp;gt; ./nft_geoip --help &amp;lt;/code&amp;gt; &amp;#039;&amp;#039;to show the script help&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The script need two .csv files.&lt;br /&gt;
&lt;br /&gt;
* A country data csv (location.csv), its path can be specified with &amp;lt;code lang=&amp;quot;bash&amp;quot;&amp;gt; --file-location &amp;lt;/code&amp;gt; option&lt;br /&gt;
* A geoip data csv (dbip.csv), its path can be specified with &amp;lt;code lang=&amp;quot;bash&amp;quot;&amp;gt; --file-address &amp;lt;/code&amp;gt; option&lt;br /&gt;
&lt;br /&gt;
=== location.csv ===&lt;br /&gt;
&lt;br /&gt;
The script ships with this file. A modified .csv that contains country data needed to generate the maps.&lt;br /&gt;
&lt;br /&gt;
=== dbip.csv ===&lt;br /&gt;
&lt;br /&gt;
This .csv &amp;#039;&amp;#039;&amp;#039;is not shipped&amp;#039;&amp;#039;&amp;#039; and needed to be retrieved before using the script. There exist the option &amp;lt;code lang=&amp;quot;bash&amp;quot;&amp;gt; --download &amp;lt;/code&amp;gt; to do so.&lt;br /&gt;
&lt;br /&gt;
== Generating the geoip maps ==&lt;br /&gt;
&lt;br /&gt;
To generate the mappings in the current directory (assuming you don&amp;#039;t have the dbip.csv file)&lt;br /&gt;
&lt;br /&gt;
  ./nft_geoip.py --file-location location.csv --download&lt;br /&gt;
&lt;br /&gt;
You can specify a different (existing) output directory with &amp;lt;code lang=&amp;quot;bash&amp;quot;&amp;gt; --output-dir &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Output files ==&lt;br /&gt;
&lt;br /&gt;
  rwxr-xr-x 2 foobar foobar 4,0K ene  4 19:38 .&lt;br /&gt;
  drwxr-xr-x 5 foobar foobar 4,0K ene  4 19:38 ..&lt;br /&gt;
  -rw-r--r-- 1 foobar foobar  22M ene  4 19:38 dbip.csv&lt;br /&gt;
  -rw-r--r-- 1 foobar foobar  956 ene  4 19:38 geoip-def-africa.nft&lt;br /&gt;
  -rw-r--r-- 1 foobar foobar 8,3K ene  4 19:38 geoip-def-all.nft&lt;br /&gt;
  -rw-r--r-- 1 foobar foobar  902 ene  4 19:38 geoip-def-americas.nft&lt;br /&gt;
  -rw-r--r-- 1 foobar foobar   15 ene  4 19:38 geoip-def-antarctica.nft&lt;br /&gt;
  -rw-r--r-- 1 foobar foobar  808 ene  4 19:38 geoip-def-asia.nft&lt;br /&gt;
  -rw-r--r-- 1 foobar foobar  810 ene  4 19:38 geoip-def-europe.nft&lt;br /&gt;
  -rw-r--r-- 1 foobar foobar  461 ene  4 19:38 geoip-def-oceania.nft&lt;br /&gt;
  -rw-r--r-- 1 foobar foobar 8,8M ene  4 19:38 geoip-ipv4.nft&lt;br /&gt;
  -rw-r--r-- 1 foobar foobar  16M ene  4 19:38 geoip-ipv6.nft&lt;br /&gt;
&lt;br /&gt;
When everything is finished you will find the following files in your output directory&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;geoip-def-all.nft&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Containing all definitions. (eg. &amp;lt;code lang=&amp;quot;bash&amp;quot;&amp;gt; define $CA = 124 &amp;lt;/code&amp;gt;) the variable name is its&lt;br /&gt;
It also contains a map between country marks and its corresponding continent mark.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;geoip-def-{continent}.nft&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Subset of definitions for countries of a given continent. To be used as marks.&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;geoip-ipv4.nft&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Containing the map between ipv4 ranges and its geoip data. &amp;lt;code lang=&amp;quot;bash&amp;quot;&amp;gt;@geoip4&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;geoip-ipv6.nft&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Containing the map between ipv6 ranges and its geoip data. &amp;lt;code lang=&amp;quot;bash&amp;quot;&amp;gt;@geoip6&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Marking packets with its country code ==&lt;br /&gt;
&lt;br /&gt;
  meta mark set ip saddr map @geoip4&lt;br /&gt;
&lt;br /&gt;
  meta mark set ip saddr map @geoip6&lt;br /&gt;
&lt;br /&gt;
== Matching packets by its country code ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;You can only use the country definitions inside your ruleset file and not inside an interactive nft shell&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
For example, to match packets marked with the Canada mark.&lt;br /&gt;
&lt;br /&gt;
  meta mark $CA&lt;br /&gt;
&lt;br /&gt;
See the relevant section in [https://wiki.nftables.org/wiki-nftables/index.php/Matching_packet_metainformation#Matching_packets_by_packet_mark Matching packet metainformation]&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
=== Marking input ipv4 packets and counting Spanish traffic ===&lt;br /&gt;
&lt;br /&gt;
  table filter {&lt;br /&gt;
    include &amp;quot;./geoip-def-all.nft&amp;quot;&lt;br /&gt;
    include &amp;quot;./geoip-ipv4.nft&amp;quot;&lt;br /&gt;
  &lt;br /&gt;
    chain input {&lt;br /&gt;
                  type filter hook input priority filter; policy accept;&lt;br /&gt;
                  meta mark set ip saddr map @geoip4&lt;br /&gt;
                  meta mark $ES counter&lt;br /&gt;
                }&lt;br /&gt;
  }&lt;/div&gt;</summary>
		<author><name>Jose</name></author>
	</entry>
</feed>