Skip to content

Commit 252b1ac

Browse files
committed
Update README
Add minimum python version required to run nft_geoip.py. Add -c/--country-filter information and replicate the main example using this parameter.
1 parent 127aa79 commit 252b1ac

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

README.md

+68
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
Python script that generates .nft files with mappings between IP addresses
44
and its geolocation, so you can include them inside your rules.
55

6+
67
# Requirements
78

9+
Minimum python version: **3.9**
10+
811
Package used that are not present in the Python Standard Library
912

1013
- `requests`
1114

15+
1216
# Usage example
1317

1418
To generate ipv4 and ipv6 mappings, download geoip data from db-ip.com
@@ -40,6 +44,28 @@ drwxr-xr-x 5 foobar foobar 4,0K ene 4 19:38 ..
4044
* geoip-ipv4.nft defines geoip4 map (@geoip4)
4145
* geoip-ipv6.nft defines geoip6 map (@geoip6)
4246

47+
## Creating a country filtered subset for `geoip-*.nft` files
48+
49+
If you don't want the whole geoip map (including all countries) you can filter
50+
by country using the `-c/--country-filter` parameter. This parameter enables
51+
the creation of the additional files:
52+
53+
- geoip-ipv4-interesting.nft
54+
- geoip-ipv6-interesting.nft
55+
56+
These files will contain nft maps with addresses related to the specified
57+
countries only.
58+
59+
For example, to generate a Spanish, French and Portuguese only subset:
60+
61+
```
62+
./nft_geoip.py --download -c es,fr,pt
63+
...
64+
Found countries: {'france': 'fr', 'spain': 'es'}
65+
Writing interesting countries file...
66+
Done!
67+
```
68+
4369
## Marking packets to its corresponding country
4470

4571
Most importantly, using the maps you mark ipv4 and ipv6 packets with
@@ -121,6 +147,48 @@ nft delete table geoip
121147
nft -f /etc/geoip.nft
122148
```
123149

150+
## Example: Counting incoming Spanish traffic (using smaller geoip map files)
151+
152+
Use the `-c/--country-filter` parameter to generate the additional files:
153+
154+
- `geoip-ipv4-interesting.nft`
155+
- `geoip-ipv6-interesting.nft`
156+
157+
For this example the command might look like this (assuming dbip.csv is not
158+
present):
159+
160+
```
161+
$ ./nft_geoip --download -c es
162+
```
163+
164+
Create a file, `geoip.nft` (it will be at `/etc/geoip.nft` for this example)
165+
and use the "interesting" files not the whole geoip maps.
166+
```
167+
#!/usr/sbin/nft -f
168+
169+
table inet geoip {
170+
include "geoip-def-all.nft"
171+
include "geoip-ipv4-interesting.nft"
172+
include "geoip-ipv6-interesting.nft"
173+
174+
chain geoip-mark-input {
175+
type filter hook input priority -1; policy accept;
176+
177+
meta mark set ip saddr map @geoip4
178+
meta mark set ip6 saddr map @geoip6
179+
}
180+
181+
chain input {
182+
type filter hook input priority 0; policy accept;
183+
184+
meta mark $ES counter
185+
}
186+
}
187+
```
188+
__NOTE:__ You can replace `geoip-def-all.nft` by `geoip-def-europe.nft`, or
189+
just copy the "define ES = ..." line into your nft file.
190+
191+
124192
# Caveats
125193

126194
__It is not possible to use the country definitions inside an interactive

0 commit comments

Comments
 (0)