How to Block an IP address in WordPress

3Shares

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.

WordPress Comments
WordPress Comments View

Below see 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.

WordPress Comment with IP Address
WordPress Comment with IP Address

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.

WordPress Settings Comments Blacklist
WordPress Settings Comments Blacklist

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:

Order Deny,Allow
Deny from 5.188.210.60

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.

Useful links

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/.

Hi, my name is Anto! I am a cloud computing hobbyist! Give me anything to do with the cloud, and I am interested. I work for a Cloud computing company by day and as a Cloud computing hobbyist by night! My projects use PHP, NodeJs, Ubuntu, MySQL and of course Amazon Web Services. Hopefully, my blog aids your cloud journey! Feel free to post a comment and share your thoughts.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.