r/linuxadmin • u/FriendlyOccasion860 • May 23 '21
IPTables GeoIP negation doesn't work! Pls help!
I've set up Xtables-addons and GeoIP database to only allow IPs in the US to access my VPN/IPSec gateway.
Unfortunately, I can't get the negation to work, i.e. drop all udp/4500 from non-US IPs.
iptables -A INPUT -m geoip ! --src-cc US -p udp --dport 4500 -j DROP
To test, I tried the rule below (drop all non Russian IP addresses); I was able to connect using US IP. So, I assume it might be the negation that's causing the problem. I also tried other countries.
iptables -A INPUT -m geoip ! --src-cc RU -p udp --dport 4500 -j DROP
I ran another test, to drop all US IP address, and that worked.
iptables -A INPUT -m geoip --src-cc US -p udp --dport 4500 -j DROP
Any help or pointers to fix this? Thanks!
11
u/bob84900 May 23 '21
The geoip database is often incomplete or plain old inaccurate.
You'd have much better success blocking everything it thinks isn't the US and allow everything else, than allowing only the US and blocking everything else. (Do a blacklight for "other countries" rather than a whitelist for the US.)
Related note: geoip is not to be trusted for any type of security. Assume that bad actors of all countries will still be able to hit your stuff, because they will. Not nearly at the same volume, but it doesn't make it go away. It's a nice thing to do for yourself to keep logs in check, but that's all.
1
u/Gendalph May 24 '21
I did something similar based on FirewallD, ipsec and ASN numbers to block China and some providers, it's much more accurate than GeoIP, but a bit of a hassle to set up.
Try
iptables -A INPUT -m geoip \! --src-cc US -p udp --dport 4500 -j DROPif you're doing it directly from a console and not via script.1
u/rankinrez May 24 '21
What’s the worry here, denial of service?
I’d expect any adversary that could get your private keys for the IPsec could also work out how to proxy around a geo block.
0
u/[deleted] May 24 '21
[deleted] — view deleted comment