Geoip blocker for Linux. Supports both nftables and iptables firewall management utilities.
The idea of this project is making geoip blocking easy on (almost) any Linux system, no matter which hardware, including desktop, server, VPS or router, while also being reliable and providing flexible configuration options for the advanced users.
Supports running on OpenWrt. Supports ipv4 and ipv6.
Core functionality is creating either a whitelist or a blacklist in the firewall using automatically downloaded ip lists for user-specified countries.
ip lists are fetched either from RIPE (regional Internet registry for Europe, the Middle East and parts of Central Asia) or from ipdeny. Both sources provide updated ip lists for all regions.
All firewall rules and ip sets required for geoip blocking to work are created automatically during installation or setup.
Implements optional (enabled by default) persistence of geoip blocking across system reboots and automatic updates of the ip lists.
After installation, a utility is provided to check geoip status and firewall rules or change country codes and geoip-related config.
If you want to change geoip blocking config or check geoip blocking status, you can do that via the provided utilities.
A selection of options is given here, for additional options run geoip-shell -h
or read NOTES.mdand DETAILS.md.
To check current geoip blocking status: geoip-shell status
. For a list of all firewall rules in the geoip chain and for a detailed count of ip ranges in each ip list: geoip-shell status -v
.
To add or remove ip lists for countries: geoip-shell <add|remove> -c <"country_codes">
Examples:
geoip-shell add -c "DE NL"
geoip-shell remove -c DE
To enable or disable geoip blocking: geoip-shell <on|off>
To change ip lists source: geoip-shell configure -u <ripe|ipdeny>
To change geoip blocking mode: geoip-shell configure -m <whitelist|blacklist>
To have certain trusted ip addresses or subnets bypass geoip blocking: geoip-shell configure -t <["ip_addresses"]|none>
. none
removes previously set trusted ip addresses.
To have certain LAN ip addresses or subnets bypass geoip blocking: geoip-shell configure -l <["ip_addresses"]|auto|none>
. auto
will automatically detect LAN subnets (only use this if the machine has no dedicated WAN interfaces). none
removes previously set LAN ip addresses. This is only needed when using geoip-shell in whitelist mode, and typically only if the machine has no dedicated WAN network interfaces. Otherwise you should apply geoip blocking only to those WAN interfaces, so traffic from your LAN to the machine will bypass the geoip filter.
To change protocols and ports geoblocking applies to: geoip-shell configure -p <[tcp|udp]:[allow|block]:[all|<ports>]>
(for detailed description of this feature, read NOTES.md, sections 9-11)
To enable or change the automatic update schedule: geoip-shell configure -s <"schedule_expression">
Example
geoip-shell configure -s "1 4 * * *"
To disable automatic updates of ip lists: geoip-shell configure -s disable
To update or re-install geoip-shell: run the -install script from the (updated) distribution directory. It will first run the -uninstall script of the older/existing version, then install the new version.
On OpenWrt, if installed via an ipk package: opkg uninstall <geoip-shell|geoip-shell-iptables>
Linux. Tested on Debian-like systems and on OPENWRT, should work on any desktop/server distribution and possibly on some other embedded distributions.
POSIX-compliant shell. Works on most relatively modern shells, including bash, dash, ksh93, yash and ash (including Busybox ash). Likely works on mksh and lksh. Other flavors of ksh may or may not work (please let me know if you try them). Does not work on tcsh and zsh.
nftables - firewall management utility. Supports nftables 1.0.2 and higher (may work with earlier versions but I do not test with them).
OR iptables - firewall management utility. Should work with any relatively modern version.
for iptables, requires the ipset utility - install it using your distribution's package manager
standard Unix utilities including tr, cut, sort, wc, awk, sed, grep, pgrep, pidof and logger which are included with every server/desktop linux distribution (and with OpenWrt). Both GNU and non-GNU versions are supported, including BusyBox implementation.
wget or curl or uclient-fetch (OpenWRT-specific utility).
for the autoupdate functionality, requires the cron service to be enabled.
For some helpful notes about using this suite, read NOTES.md.
For specifics about each script, read DETAILS.md.
For information about OpenWrt support, read the OpenWrt README.
geoip-shell does not share your data with anyone. If you are using the ipdeny source then note that they are a 3rd party which has its own data privacy policy.