Steps to Block IP Addresses with .htaccess file
Here in this post i am going to explain how to deny an IP address or how to allow only a particular IP address to access your site
This will helps and useful for you to protect your websites from hackers or to block any unwanted visitors.
For this you need to create an .htaccess file in your public_html folder and add these lines below, based on your requirements.
To Deny a Specific IP Address
Type the below code it will only deny one IP address from accessing the website.
Deny from 126.96.36.199
Just change the above IP address to the IP address that you want to deny and paste it in the .htaccess file.
To Deny a Specific Domain
We can able to deny a specific domain from accessing our domains by adding the below line of code to your .htaccess file.
Deny from 188.8.131.52/255.255.255.0
You need to change the IP address and netmask value to match the domain that you want to block.
To Deny Multiple IP’s in a Single Line of Code
For this you leave a blank space with each IP for separation.
Deny from 184.108.40.206 220.127.116.11 333.333.333.333
All you need to do is replace the IPs that you want to deny and paste it in the .htaccess file.
To Allow Only a Single IP
The below set of .htaccess rule will deny access to your website from every IP address expect the IP address mentioned in the rule.
Order Deny,Allow Deny from all Allow from 18.104.22.168
Here we first deny all visitors, and then allow only the visitor from the IP address specified above.
To check log entries for total no of connections to a Port From an IP Address.click