In this tutorial, we will learn how to deny an IP address or how to allow a particular IP address from accessing your website. This measure is taken to save the website from hackers or to block unwanted visitors.
First of all, you will need to create a .htacsess file in your public_html folder and add the following lines as per the requirements:
1) Code to deny a specific IP address –
Deny from 184.108.40.206
This code will deny one IP address from accessing your website. Make sure you use the IP address for which you wish to work.
2) Code to deny specific domain –
Deny from 192.0.0.1/366.366.366.0
Using this code you can deny a specific domain from accessing your domain. Use the code in .htaccess file, and replace IP address and netmask value to match the domain that you wish to block.
3) Code to deny multiple IP’s in a single line of code –
While using this code, leave a blank space with each IP for separation.
Deny from 220.127.116.11 444.444.444.444 666.666.666.666
Replace IPs of your choice in .htaccess file.
4) Code to allow only a single IP –
The below code will deny access of all the other websites from every IP address except the IP address mentioned in the rule :
Order Deny,Allow Deny from all Allow from 18.104.22.168
This code indicates that first, we have denied all visitors and then allowed only the visitor from a specified IP address.
5) Code to deny single IPv6 address –
Use the following code to block IPv6 address through .htaccess file :
Deny from 2001:cdba:0000:0000:0000:0000:3284:7536
Also Read :