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! This post discussed blocking a specific spammer’s IP.
Recently, my WordPress blog (https://anto.online) got spammed on a daily basis. I expect an occasional WordPress spam comment, but thousands of spam comments in one day is quite annoying! Fortunately – the spammers were not successful due to the spam filtering features implemented in WordPress. 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 an extremely popular 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 see an example of the IP address that is spamming my WordPress blog. In this case, it is 184.108.40.206, but I have noticed this IP address is one of a few ranging from 220.127.116.11 – 18.104.22.168.
For information sake, I looked up the IP address using CleanTalk’s blacklist 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.
Using the IP address from the comments section, navigate to the WordPress settings section and add the offending IP address to the comment black list. Notice that you can add multiple IP addresses here, so I added all the IP addresses that 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 which is 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:
Deny from 22.214.171.124
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.
The http://www.htaccesstools.com/block-ips/ website is great to lookup IP addresses on a spam blacklist. You can use https://anto.online/tools/what-is-my-public-ip/ to determine your public IP. See this great post by Neeraj Agarwal if you prefer using plugins.
I hope you liked this post. If so, please click the like button and you will receive a million years of good Luck! Feel free to read other great posts at https://anto.online/.
About the Authors
Anto's editorial team loves the cloud as much as you! Each member of Anto's editorial team is a Cloud expert in their own right. Anto Online takes great pride in helping fellow Cloud enthusiasts. Let us know if you have an excellent idea for the next topic! Contact Anto Online if you want to contribute.
Support the Cause
Support Anto Online and buy us a coffee. Anything is possible with coffee and code.