In this article we’ll cover how you can blacklist or whitelist an IP on your website with the help of .htaccess or Cloudflare. We’ll also discuss why and when you should want to do so.
Table of contents
What is IP blacklisting?
IP blacklisting is a method to block all (malicious, illegitimate or not wanted) traffic to your website by blocking IP addresses.
What is IP whitelisting?
IP whitelisting is the opposite of IP blacklisting where you grant an IP access to your website instead of blocking it.
When and why should I want to blacklist or whitelist an IP?
Blacklisting an IP (blocking) from accessing your website should be done if you experience malicious, illegitimate or not wanted traffic to your website from one or more IP addresses. Blacklisting an IP can result in your website being more secure and can prevent your website from going down due to a DDoS attack for example.
Whitelisting an IP (granting) should be done if you want to give one or more IP addresses access to your website. Combining blacklisting and whitelisting could be particularly useful if you are developing a website and want to only give certain IP addresses access to your website and block all others
Blacklist/whitelist IP’s in .htaccess
You can whitelist / blacklist any IP addresses of your choice by editing the
.htaccess file on your server.
This is an example on how to only whitelist your IP address:
order deny,allow deny from all allow from <your ip>
This is an example on how to blacklist an IP address:
Deny from <your ip>
Blacklisting an IP using
.htaccess will give the blocked IP a 403 Forbidden HTTP status code if they try to visit your website:
Blacklist/whitelist IP’s in Cloudflare
If you have Cloudflare attached to your website then you can make an IP Access Rule:
- Log in to your Cloudflare account.
- Select your domain.
- Click the Security app.
- Click on the Tools tab.
- Under IP Access Rules, enter the following details:
- Enter the Value as an IP, IP range, or two-letter country code.
- Select an Action. Block = Blacklist. Allow = Whitelist
- Select whether the rule applies to This website or All websites in the account.
- (Optional) add a Note (i.e. Payment Gateway).
- Click Add.
And as always, should you have any additional questions please don’t hesitate to contact our support chat at servebolt.com!
Give us your feedback on this article
Servebolt has launched Accelerated Domains!
Accelerated Domains is a service that greatly improves and optimizes your site on these four areas: Performance, Scalability, Security and the Carbon footprint of your website.