Blocking an IP address means telling one specific system to refuse traffic from one specific network position. You can do it at your device firewall, your router, your web server, your CDN, or inside your application — and the layer you pick decides whether the block actually helps or quietly breaks something you needed. Most guides skip that decision entirely and jump straight to commands.
Here is the number that should shape every choice you make on this page. In Cloudflare's H1 2026 DDoS report, 90.60% of network-layer attacks ended in under ten minutes. By the time a human reads an alert, opens a config file, adds a rule and reloads the service, the attack is over and the address has moved on.
That does not make blocking useless. It makes blocking an architecture decision rather than an emergency reflex. This guide covers which layer to block at, whether to block a single address or a whole range, who you are likely to lock out by accident, and the cases where blocking is the wrong tool entirely.
The worst outage I ever helped unpick was self-inflicted. A team facing a scraping problem blocked a /16 at the edge, and inside four hours their payment processor's callback traffic was landing in the same range. Nobody connected the two. I spent an afternoon reading firewall counters to find it. Since then I ask one question before any IP block goes live: what else lives in this range?
My honest position is that blocking is overrated as a defence and underrated as a filter. It will not stop a determined attacker, who rotates addresses faster than you can add rules. It will cut noise, protect a login endpoint, and buy time. Treat a blocklist as housekeeping rather than security, and you will make far better decisions about what belongs on it.
Quick Answer: How to Block an IP Address
Block an IP address at the highest layer that still sees the traffic: CDN or WAF for websites, server firewall for applications, router for a home network. Always confirm what you are blocking before you write the rule, because shared and recycled addresses cause most accidental lockouts. Start by running the address through an ownership and network check.
What Does Blocking an IP Address Actually Do?
Blocking an IP address configures one system to drop or refuse connections originating from that address. It affects only the system holding the rule. Your web server rejecting an IP address does nothing about that address reaching your mail server, your SSH port, or any other host you own. Nothing is removed from the internet, nothing is reported anywhere, and the person behind the address is usually never told.
Two mechanics matter more than the syntax. A drop silently discards the packet and leaves the sender waiting for a timeout. A reject sends a refusal back, which is faster for the sender and reveals that something deliberately turned them away. Drop hides the rule; reject is politer to legitimate users who got caught by mistake.
Scale explains why this question comes up so often now. Cloudflare's H1 2026 DDoS Threat Report recorded 23.2 million network-layer attacks and 29.64 trillion HTTP DDoS requests between January and June 2026 — roughly 5,343 network-layer attacks every hour. Hostile traffic is now ordinary background conditions rather than an event.
What blocking cannot do
It cannot stop someone who controls more than one address, and most attackers do. It cannot identify anyone, and it cannot protect a system that does not enforce the rule. Nor does it apply retroactively: a block added today does nothing about credentials someone harvested yesterday. Blocking narrows a doorway; it does not undo what already walked through.
Knowing what the action does still leaves the first real decision unmade, and getting it wrong is what wastes most people's afternoon.
Which Layer Should You Block At?
Block at the highest layer that still sees the traffic. Higher layers stop unwanted requests before they consume your bandwidth, your CPU, or your application logic. A CDN rule rejects a foreign request entirely; a rule inside WordPress rejects it only after PHP has already loaded and your database has already been queried. Same outcome for the visitor, wildly different cost to you.
The exception is visibility. Higher layers often hide the original address behind their own, so a server-level rule written after a CDN sits in front of it will match the CDN rather than the visitor. Anyone who has blocked an IP address in .htaccess and watched it keep arriving has met this problem.
| Layer | Blocks Before It Costs You | Best For | Main Weakness |
|---|---|---|---|
| CDN / WAF | Bandwidth, server, application | Websites behind Cloudflare or similar | Plan limits; rules capped per account |
| Cloud security group | Instance CPU and application | AWS, Azure, GCP workloads | Rule count limits per group |
| Server firewall | Application and database | VPS, dedicated servers, SSH defence | Traffic already reached your bandwidth |
| Web server config | Application logic only | Apache and Nginx virtual hosts | Sees the proxy address, not the visitor |
| Application / CMS | Nothing — everything already ran | Per-user bans, comment spam | Most expensive place to say no |
| Home router | Everything on the LAN | Household devices and parental control | Dynamic addressing defeats it quickly |
| DNS resolver | Connection never starts | Outbound control across a fleet | Blocks names, not addresses |
That last row confuses people, so it earns a clarification. DNS filtering stops a device resolving a hostname, which prevents the connection from ever starting — a separate mechanism with separate strengths. IP address blocking and name blocking solve overlapping problems, and mature setups run both.
Layer chosen, the next decision determines your blast radius — and this is where people cause real damage.
Should You Block One IP, a Range, an ASN, or a Country?
Match the scope to how the traffic behaves. A single IP address suits a one-off nuisance, while a CIDR range (a block of consecutive addresses written as a prefix and a length, such as 203.0.113.0/24) suits an attacker rotating within one subnet. An ASN block covers an entire network operator, and a country block covers everything mapped to one nation. Each step up multiplies both your protection and your collateral damage.
| Scope | Addresses Affected | Use When | Collateral Risk |
|---|---|---|---|
| Single address | 1 | One persistent nuisance visitor | Low — unless it is shared or recycled |
| /24 range | 256 | Rotation inside one subnet | Moderate — often one customer's block |
| /16 range | 65,536 | Rarely justified outside incidents | High — this is where outages happen |
| ASN | Every range one operator announces | Abusive hosting or scraping provider | High if the ASN also serves consumers |
| Country | Millions | Compliance or a market you never serve | Very high — and trivially bypassed |
Why ASN Often Beats Country
Blocking a hosting provider by its autonomous system number is usually sharper than blocking a country. Abuse concentrates in specific networks rather than spreading evenly across a nation, so an ASN rule removes the source while leaving that country's ordinary residential users reaching you normally. Country rules do the opposite: they punish millions of consumers and miss the attacker who rents a server elsewhere.
Both approaches need arithmetic before they need config. Convert your target into clean prefixes with a CIDR range calculator before pasting anything into a firewall, and if prefix notation is unfamiliar, our explainer on how subnet masks divide address space covers the underlying maths in plain terms.
Scope decided, the mechanics differ by platform — and the differences are larger than most tutorials admit.
How Do You Block an IP Address on Each Platform?
Every platform expresses the same idea with different syntax and different failure modes. Apache uses directives in configuration or .htaccess, and cPanel wraps that same mechanism in a screen labelled IP Address Deny Manager, while Nginx uses deny inside a server block. Linux offers iptables, nftables or ufw; Windows uses inbound rules with a scope tab; Cloudflare uses WAF custom rules. The concept transfers everywhere, and the mistakes do not.
| Platform | Mechanism | The Gotcha Most People Hit |
|---|---|---|
| Apache / cPanel | Directives in .htaccess or vhost config | Behind a proxy it matches the proxy, not the visitor |
| Nginx | deny directives in the server block | Needs real_ip configured or every visitor looks identical |
| Linux firewall | iptables, nftables or ufw | Rules vanish on reboot without persistence configured |
| Windows | Inbound rule, Scope tab, remote addresses | Profile mismatch — rule set for Domain, machine on Public |
| Cloudflare | WAF custom rules or IP Access rules | Country blocking via IP Access rules is Enterprise-only |
| Home router | Access control or firewall rules | DHCP reassigns the address and the rule misses |
| WordPress | Security plugin blocklist | Comment blocking is not site blocking — check which one you enabled |
| Hosts file | Maps a hostname to 127.0.0.1 locally | Blocks names not addresses, and only on that one machine |
The Cloudflare row deserves a footnote because guidance changed. Cloudflare now recommends custom rules rather than IP Access rules for both address-based and geography-based blocking, notes that blocking by country through IP Access rules requires an Enterprise plan, and caps each account at 50,000 IP Access rules. Plenty of tutorials still teach the older path.
Syntax is the easy part. The expensive part is discovering, days later, who else you removed.
Who Are You About to Block by Mistake?
Assume every IP address you block is shared until you prove otherwise. Mobile carriers place hundreds of subscribers behind one public IP address using carrier-grade NAT, and corporate networks present thousands of employees as a handful of addresses. Schools, hotels and hospitals do the same. Blocking one abusive visitor on a shared line removes everyone else standing behind it, and none of them will tell you.
Search crawlers are the other common casualty, and this one costs money. A user agent string is a claim, not proof — anything can call itself Googlebot. Blocking a range that contains the genuine crawler will deindex pages, while a fake crawler simply changes its label and continues. Verify before you block, never after.
The check that takes thirty seconds
Before any rule involving a crawler, confirm the IP address genuinely belongs to the operator it claims. Forward-confirmed reverse DNS and published address ranges both settle it. Run it through a crawler authenticity check first. As of August 2026, impersonation is common enough that treating the user agent as evidence is simply a mistake.
Geo-blocking produces the most avoidable version of this failure. Organisations have blocked their own cloud services after discovering their hosting provider routed traffic through countries the allowlist never covered. The rule looked correct; the dependency map was wrong.
Suppose you avoid every one of those mistakes. Your block will still stop working, and understanding why changes how you use it.
Why Do Most IP Blocks Stop Working Within Hours?
IP addresses move, and attackers move faster than your maintenance schedule. Residential connections get a new IP address on reconnection, and mobile devices change addresses between towers. Attackers rent fresh servers by the hour, while residential proxy networks supply millions of ordinary home connections to route traffic through. A blocklist built by hand therefore ages out roughly as fast as one person can maintain it.
Speed makes it worse. Since 90.60% of network-layer attacks finish inside ten minutes, according to Cloudflare's H1 2026 figures, manual blocking arrives after the event nearly every time. Automated rules that add and expire entries on their own do useful work here; a person watching a dashboard does not.
Rotation Is the Business Model Now
Analysis of roughly four billion sessions between late 2025 and early 2026 found that 39% of unique sources hitting network edges came from residential connections, and 78% of them rotated away before any reputation system could flag them. Blocking assumes an IP address is a stable identifier. For a professional operation it is a consumable.
Temporary Blocks Beat Permanent Ones
The fix for rotation is not a longer list; it is a shorter memory. Automated tools watch logs for a pattern, add an entry when the pattern trips, then remove it after a set interval without anyone touching a config file. An hour is enough to break a brute-force loop. A permanent entry, by contrast, keeps punishing whoever inherits that address six months later.
Expiry also solves the maintenance problem that kills hand-built lists. A firewall carrying forty thousand stale entries costs lookup time on every packet and nobody remembers why half of them exist. Rules that clean up after themselves stay small enough to reason about, which matters more than raw coverage.
There is a second reason to prefer short bans. Blocking is loud. A sustained refusal tells a competent attacker exactly which detection threshold they crossed, and they will tune around it. A brief, quiet ban leaks far less information about how your defences work.
Forged source addresses add a further limit. Traffic can arrive claiming an address its sender never held, which our guide to detecting forged source addresses works through in detail. Filtering on a value the attacker controls has obvious limits.
None of that argues for doing nothing. It argues for picking the right instrument, and blocking is only one of four.
When Is Blocking the Wrong Tool?
Blocking is binary and permanent until you remove it, which makes it the wrong response to anything ambiguous. Rate limiting suits traffic that is welcome in small amounts and hostile in large ones, and challenges suit traffic you suspect but cannot confirm. Authentication suits anything sensitive enough that source address should never have been the control. Reach for an IP address block when the source is unambiguous and the volume is low.
| Situation | Better Tool | Why Not Blocking |
|---|---|---|
| Aggressive but legitimate scraping | Rate limiting | You want the traffic, just less of it |
| Suspicious login attempts | Challenge, then MFA | Real users share those addresses |
| Distributed attack, thousands of sources | Upstream DDoS mitigation | You cannot write rules fast enough |
| Protecting an admin panel | Allowlist plus authentication | Deny-lists are open by default |
| One address, one clear abuser | Blocking — correct choice | Cheap, precise, easy to reverse |
Row four holds the strategic point. An allowlist denies everything except what you permit, which inverts the maths in your favour. You maintain a short list of known-good sources instead of an endless list of known-bad ones. That principle sits at the centre of never-trust-by-default network design, and for administrative endpoints it beats any blocklist you could build.
Volume explains why. Automated traffic reached 53% of all web traffic during 2025 in the Imperva 2026 Bad Bot Report, with bad bots at 40% and human visitors down to 47%. You cannot enumerate a majority.
Whichever instrument you choose, one step separates a working rule from an assumption — and most people skip it.
How Do You Verify a Block Worked and Undo It Safely?
Test from outside, not from your own connection. A rule that looks correct in a config file proves nothing until traffic from the blocked range actually fails to arrive. Equally important, every rule needs a written reason and a review date, because an unexplained entry from two years ago is the one nobody dares remove and the one quietly costing you customers.
Six Steps Before And After Any Block
1 Identify what the address actually is
Check which operator holds it, whether the range is residential or hosting, and whether it belongs to a search crawler or a payment provider. Two minutes here prevents most self-inflicted outages.
2 Choose the narrowest scope that works
Start with the single address. Widen to a prefix only when you can see rotation in the logs. Never open with a /16 because it feels decisive. That is exactly how the payment callback disappears.
3 Write the rule with a comment
Record the date, the reason, and who approved it. Most firewall syntaxes accept an inline comment. A blocklist without reasons becomes permanent through fear rather than judgement.
4 Test from an outside connection
Use a connection inside the blocked range where possible, or a service that requests your site from elsewhere. Confirm the block, then confirm ordinary visitors still get through.
5 Watch what changed for an hour
Check error rates, checkout completions, crawler hits and support tickets. Collateral damage shows up in business metrics long before anyone reports it as a firewall problem.
6 Set an expiry and review it
Give every entry a review date. Addresses get reassigned to innocent parties constantly, and hardening the wider setup matters more anyway — our guide on reducing what attackers can reach in the first place covers that side.
Step five is the one experienced admins add after being burned once. Firewall logs tell you a rule fired; business metrics tell you whether it fired at the right people.
That is the full decision path, from layer to scope to verification. The summary below is what to keep.
The Short Version
Block at the highest layer that still sees real visitor IP addresses, and remember that a rule written below a CDN will match the CDN instead. Pick the narrowest scope the evidence supports, widening from a single address to a prefix only when logs show rotation. Blocking a hosting provider by ASN usually beats blocking a country, because abuse concentrates in networks rather than spreading evenly across nations.
Expect shared addresses everywhere. Carrier-grade NAT, corporate gateways and public networks mean one blocked IP address often represents hundreds of people. Verify any crawler before blocking it, since a user agent is a claim rather than proof, and deindexing your own pages is an expensive way to learn that.
Above all, treat blocking as housekeeping rather than defence. With 90.60% of network-layer attacks finishing inside ten minutes and automation now the majority of web traffic, hand-written rules will always arrive late. Automate expiry, prefer allowlists for anything administrative, and check what an IP address really is before you write anything — a quick look at the experience from the blocked visitor's side is a useful corrective before you press save.
Know What You Are Blocking
Every range belongs to an operator, and that operator decides how much collateral damage your rule causes. Check the network behind it before you write it into a firewall. Free, instant, no account.