Table of Contents
Looking to block a specific IP address from accessing your website? Maybe you saw some rogue activity, and its coming from a specific IP?
Perhaps some IP address you can see spidering through all your content – and its not a search robot?
Whatever the reason, if you’re looking to block a specific IP address from accessing your website, the range of options below will allow you to do just that.
Block IP Address Using .htaccess
If your site is served with Apache, and you have .htaccess files enabled (used httpd.conf if not – outside of scope for this part though!), then you can add 1 line to block a specific IP address from accessing, and that line looks like this:
The Gist above will show you what to add, but basically, you are saying to deny this specific IP address from this directory, and anything “below” it – so drop this into the root directory to block from everything, or a specific sub-directory to block just this directory. For example, we describe using something similar to restrict access to the WP-admin directory in WordPress, here.
If you use CloudFlare on a free or paid plan, you can click “Firewall” and then scroll down to add IP addresses to “Block” as many times as you like. Visitors from that IP will be blocked from even hitting your server – which can be a huge benefit if you’re getting a lot of bandwidth usage from a few rogue IPs.
Using your Web Host’s Tools
Some good web hosts offer tools to block traffic by IP address, perhaps because they don’t use plain Apache as a web server (instead they use Nginx, perhaps, as a caching layer (in front of Apache), or on its own) and therefore, .htaccess isn’t the way to get this done “before” it hits your services. Hosts like Kinsta, for example, fall into this category. On Kinsta, you can use the IP Deny tool in your admin panel to block traffic by IP – have a look around your hosting control panel for similar options.
Want more options?
We’ll be adding to this item over time, but if you want specific additional options, then please leave a comment, below.