This post shows you how to block an IP address in WordPress. Why would you need to do this? Well, it turns out that there are many reasons! First, this post discussed blocking a specific spammer’s IP.
Recently, my WordPress blog (https://anto.online) got spammed daily. Of course, I expect an occasional WordPress spam comment, but thousands of spam comments in one day is quite annoying! Fortunately – the spammers were unsuccessful due to the spam filtering features implemented in WordPress. But, unfortunately, this created more traffic, used more bandwidth, consumed more space, and wasted my time.
Any good WordPress site has some sort of spam filter enabled. Akismet is a top-rated spam filter, but you could use others such as Anti-Spam by CleanTalk. There are many more anti-spam services available. A spam filter is essential if you allow comments and allow pingbacks and trackbacks. I use Akismet since it is quite successful at blocking spam; it is also an official free plugin.
Blocking an IP address using WordPress
You can identify the offending IP address by looking at the comments section in WordPress.
Below is an example of the IP address that is spamming my WordPress blog. In this case, it is 5.188.210.66, but I have noticed this IP address is one of a few ranging from 5.188.210.60 – 5.188.210.80.
For information sake, I looked up the IP address using CleanTalk’s blocklist checker, which is available at https://cleantalk.org/blacklists/. This showed me that this IP address originates from Russia, and it had a 67% spam rate.
Navigate to the WordPress settings section and add the offending IP address to the comment blocklist using the IP address from the comments section. Notice that you can add multiple IP addresses here, so I added all the IP addresses I wanted to block.
Other Methods to block IP addresses for WordPress
There are other methods to block an IP address for WordPress. Many bloggers prefer using the .htaccess file in the WordPress root folder on the Linux hosting server. The .htaccess file will not only prevent the IP address from posting comments, but rather it will stop that IP address from accessing the WordPress site completely! This is a slightly harsh approach but may be warranted if the IP address is attempting more evil acts other than spamming you.
The syntax to block an IP address using the htaccess file is this:
Order Deny,Allow
Deny from 5.188.210.60
First, you will need to copy the code into a text file and upload it to your site. The text file should be renamed to .htaccess. You can also use this handy tool to help you with the .htacess file creation: http://www.htaccesstools.com/block-ips/.
Some hosting service providers also provide facilities to block IP addresses using hosting panels such as CPanel. See below:
The CPanel IP Blocker is great since it provides many options to block IP addresses.
You can block a specific IP address such as ‘192.168.1.100’. The IP Blocker also allows entire IP address ranges such as ‘192.168.1.1-192.168.1.20’
It supports both IP v4 and IP v6 addresses.
Be careful, though! These settings will affect your entire site. Use .htaccess if you wish to block specific areas f your site. As discussed, the WordPress admin interface also allows blocking, but it is limited to comments.