Family Encyclopedia >> Electronics

How to Block IP Addresses in WordPress: Protect Your Site from Spam and Attacks

Want to secure your WordPress site by blocking specific IP addresses? As experienced WordPress users, we've relied on IP blocking to stop spam, hacking attempts, and DDoS attacks effectively. In this guide, we'll walk you through identifying suspicious IPs and blocking them step by step.

How to Block IP Addresses in WordPress: Protect Your Site from Spam and Attacks

What is an IP address?

Think of the internet like the physical world: an IP address is your device's unique identifier, much like a house number on a street. It's four sets of numbers (0-255) separated by dots.

Every internet-connected device receives an IP address from its Internet Service Provider (ISP).

Your WordPress site's access logs record the IP addresses of every visitor. Websites you visit store your IP too. For privacy, use a reputable VPN to mask your IP and personal details.

Why and when should you block IP addresses?

Blocking IPs is a reliable defense against unwanted traffic, comment spam, hacking probes, and DDoS attacks that can slow or crash your site.

DDoS signs include frequent downtime or sluggish page loads.

Spam is obvious in comments or contact forms. While we recommend anti-spam plugins first, IP blocking is a powerful last resort.

How to identify IP addresses to block in WordPress

WordPress logs commenter IPs. Check them in your admin dashboard under Comments.

How to Block IP Addresses in WordPress: Protect Your Site from Spam and Attacks

For DDoS or heavy attacks, review your server's access logs.

Log into cPanel, find the Logs section, and click Raw Access Logs.

How to Block IP Addresses in WordPress: Protect Your Site from Spam and Attacks

Click your domain to download the .gz file. Extract it with 7-Zip or WinZip, then open in Notepad or TextEdit.

Each line starts with the requesting IP.

How to Block IP Addresses in WordPress: Protect Your Site from Spam and Attacks

Avoid blocking legit users or search engines. Use online IP lookup tools to vet suspicious ones. Look for high request volumes from one IP. Tip: We'll cover automation later.

Copy suspect IPs to a text file.

Blocking IPs via WordPress settings

To stop specific IPs from commenting (but allow site access):

Go to Settings » Discussion and add IPs to the Comment Blacklist box.

How to Block IP Addresses in WordPress: Protect Your Site from Spam and Attacks

Save changes. They'll get an error on comment submission.

Blocking IPs completely with cPanel

For full access denial (ideal for hacks/DDoS):

Log into cPanel, go to Security » IP Blocker (or IP Deny Manager).

How to Block IP Addresses in WordPress: Protect Your Site from Spam and Attacks

Add single IPs or ranges, then click Add.

How to Block IP Addresses in WordPress: Protect Your Site from Spam and Attacks

Return anytime to remove.

When manual blocking falls short: Automate with a WAF

Manual blocking works for targeted threats, but sophisticated attacks use rotating global IPs—impossible to track manually.

Enter Web Application Firewalls (WAFs). Sites like WPBeginner trust Sucuri, a proven security service. It routes traffic through protected servers, scanning for threats and auto-blocking bad IPs.

Sucuri blocked 450,000 WordPress attacks for us in just 3 months.

We hope this expert guide helps you block IPs effortlessly in WordPress. Check our beginner's WordPress security guide next.

Subscribe to our YouTube channel for video tutorials. Follow us on Twitter and Facebook.