Block Particular IP to Protect Your Website

A website is like a child to its author and administrator and saving it from unwanted attack and hack is the first priority of any webmaster/blogger. Nowadays we have many platforms where we can blog. Some of the best example of blogging platform are WordPress and blogspot. Though you can also start your own custom site but saving it from attack is the main concern. There are many ways in which you can prevent unauthorized access to your blog.

 

Block Particular IP to Protect Your Website

 

Best Method to Save Your Website from Attack

 

There has been a lot discussion over the best methods to save the website from an attack like changing login page in WordPress, using a 2-way authentication system for blogger, blocking the IP from a particular system and country, using a plugin in WordPress to limit the login, etc. etc.

 

Recommended Article: Plugin to Save WordPress Blog from Virus

 

But one of the best methods is the use of blocking particular IP which is bothering you. This can be done using htaccess file in your hosting file manager.

 

How to Block IP Address using htaccess File

 

To block a particular IP address, just login to the root of your hosting account and click edit on ‘htaccess file’ and add the below lines.

order allow,deny
deny from 222.45.6.7
deny from 123.34.5.
allow from all

In the above lines, we have used IP 222.45.6.7, which we have to block and adding IP series 123.34.5., which will deny all the sub IP which start from 123.34.5.XX

After adding the above lines, your .htaccess file will look like below.


RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L] RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

order allow,deny
deny from 222.45.6.7
deny from 123.34.5.
allow from all

 

Please note that don’t block your Content delivery network a.k.a CDN IP as sometimes you will see IP address of your CDN network. If you do so your website will not be accessible. And most important don’t block your own IP. 🙂

Do let us know what are your thoughts about this article and if you are using some other methods to safeguard your website from attacks.

3 Comments