-
My use case is the following: So I don't need any incoming connection other than from my country. So here goes: (How) can I easily reverse the logic to just allow traffic to/from a country specified and block all others? (Or is there some sort of parseable list of all countries so I can block all and then just remove my own country?) Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hello, Setting things up as you describe is pretty straightforward. You can use one of the example
You can save the
Next, add an incoming firewall rule for HTTP/HTTPS to the input chain in your
The firewall rule above does three checks on the incoming packet. The first checks if the source IP address of the packet is included in one of the IP address ranges from your country code that’s stored in the If you ever need to geolocation filter outgoing packets in your output chain, you’ll want to match the destination IP address (daddr) rather than the source IP address (saddr) of the packet so that traffic is only allowed out to your country. The following rule only does two checks, and it allows packets out to new or existing connections.
For outgoing packets headed to update servers in other countries, you can place those rules in your output chain before the geolocation rule above. Please test these rules and let me know if you find any issues or typos. I hope that gets you going in the right direction. Let me know if you have any other questions. If you like the program, please consider giving the project a star at the top of the project page as it helps others to find the program here on GitHub. Thanks |
Beta Was this translation helpful? Give feedback.
-
Sorry, I've been too busy to get around to doing this. Now this totally makes sense. geo-nft just builds sets, whatever I do with them is a different story. I somehow thought it would build rules as well from just reading the docs. Apart from the quotes in your code lines that should read I went the ipv4+ipv6 route as I don't know, maybe v6 will be in (actual, broad :-) ) usage somewhen. It works with geo-inet4 just as nicely. Just took me a little to notice the commented
somehow made me think that's only for system startup and I'll need it later on, if testing shows everything is working as expected. It is pretty obvious now that the sets cannot work without actually including them. Is there a specific reason why you did not suggest the netdev table? PS: I am in no way affiliated with this service, but I found https://dnstools.ws to be pretty practical. I tested all my config with ICMP before touching anything more serious, and luckily my country is on their ping source list, so it's really easy to see when country filtering works or not! |
Beta Was this translation helpful? Give feedback.
Hello,
Setting things up as you describe is pretty straightforward. You can use one of the example
nftables.conf
files in the Wiki to test your configuration. I’ll assume that you’re using IPv4 only, but you can adjust the instructions accordingly if using IPv6 or both. Start with the example IPv4nftables.conf
file from the Wiki. You can use thegeo-ip4
nftables set in theip filter
table to store the IP address ranges for your country code. I’ll assume that your country code is AD, just like the example in the IPv4nftables.conf
file. Thegeo-ip4
nftables set will store IP address ranges for your country code, and your firewall rules will decide whether you accept or drop packets that m…