How to Block Entire Countries From Your Linux Server (Free Geo-Blocking with nuDefend)
If you run a public Linux server - a website, an API, a game server, a database, or a home lab exposed to the internet - you have almost certainly seen it in your logs: a constant stream of login attempts, port scans, and probes. Most of that traffic is automated, and a large share of it comes from a small number of countries where you have no users and do no business.
You cannot patch your way out of raw exposure. Every open port is a door, and every door gets knocked on thousands of times a day. One of the simplest, highest-impact things you can do is to stop answering the door for entire regions you will never serve. That is what geo-blocking does, and nuDefend now includes it for free.
What is geo-blocking?
Geo-blocking (also called country blocking) filters traffic based on the country an IP address belongs to. Instead of reacting to individual bad actors one IP at a time, you make a decision at the country level: allow this country, block that one.
There are two ways people usually want to use it:
- Blocklist mode: allow the whole world, but block a specific set of high-risk countries you never expect legitimate traffic from.
- Allowlist mode: block the whole world, and allow only the handful of countries where your real users actually are.
Both are valid. Blocklist mode is a gentle noise reducer. Allowlist mode is a strict lockdown that shrinks your attack surface dramatically - ideal for internal tools, admin panels, and servers that only serve one region.
Why country-level filtering works so well
Attackers rely on volume. Botnets scan enormous ranges of the internet looking for anything that responds. When you drop traffic from regions you do not serve, three things happen at once:
- Your logs get quiet. The background noise of scans and brute-force attempts drops sharply, so real anomalies actually stand out.
- Your attack surface shrinks. A vulnerability can only be exploited by someone who can reach the port. If they cannot connect, the exploit never starts.
- Your server does less work. Every blocked connection is CPU, memory, and bandwidth you get back for real users.
Geo-blocking is not a silver bullet, and it is not meant to replace patching, strong authentication, or a real firewall policy. It is a first, cheap layer that removes a huge amount of hostile traffic before anything else has to deal with it.
The catch with doing it yourself
You can build country blocking by hand. The usual recipe is to download IP-to-country data (for example from a GeoIP provider), turn it into thousands of network ranges, load them into ipset or nftables, and write a cron job to refresh the list as the internet re-allocates address blocks.
It works, but it comes with sharp edges:
- The country data goes stale within weeks, so a manual list slowly stops matching reality.
- One wrong rule can lock you out - including the country your own server sits in.
- Large IP sets can be heavy if you load them the wrong way.
- You own the whole thing forever: updates, testing, and the 2 a.m. debugging when a rule misfires.
Most people set it up once, then never touch it again, which is the worst outcome: a security control that quietly rots.
How nuDefend does it
nuDefend is a lightweight security agent for any Linux server, on any cloud or on-premise. It already blocks known-malicious IP addresses and domains, inbound and outbound, and refreshes its threat list automatically every 30 minutes. Country blocking is built into the same agent, so there is nothing extra to install.
A few things make it safe to actually leave on:
- One click per country. Pick the countries you want to allow or block from a simple dashboard. No config files, no ipset syntax.
- It never locks you out. nuDefend always keeps the country your server runs in reachable, even in allowlist mode, so you cannot accidentally strand yourself.
- Inbound and outbound. Rules apply in both directions, which also helps stop compromised processes from calling out to regions you never talk to.
- Instant to reverse. Change your mind and the rules update immediately. Nothing is permanent.
- Self-updating and self-healing. The underlying data stays current automatically, and the agent restores its own rules if anything tampers with them.
Included free, right now
Country blocking is available free with every nuDefend license at this stage. If you already run nuDefend, the feature is in your dashboard - open it, choose your policy, and you are done. If you do not, a single command installs the agent and you can turn geo-blocking on in the first minute.
Cutting off the regions you never serve is one of the rare security wins that is both easy and genuinely effective. Start with blocklist mode to quiet the noise, and move to allowlist mode when you are ready to lock things down.
Ready to try it? Head to nuvpn.com/nudefend to get started.