WordPress Tutorial

How to Block IP Addresses Using IP Manager and .htaccess

Having a problem with malicious users that try to threaten your website’s security? We’ve got you covered. In this article, we’ll give you the steps on how to block an IP address using Hostinger’s IP Manager tool and .htaccess. In addition, we’ll teach you how to do geo-blocking with .htaccess which is how you can block an entire country from accessing your site.

Why Would You Want to Block IP’s?

It’s a common knowledge that the internet is an open space where everyone across the world has access to it 24/7. Consequently, your website is no different. While online businesses see this as an opportunity to gain revenue, from another side of things, it’s a potential threat to users’ privacy and security.

Why so? Criminals exist in the world, and there are no bounds whether it’s in your city or your website. These individuals take the form of spammers, hackers, and toxic users.

Harmful intentions vary in terms of the level of harm some people want to commit. The best case scenario is that they post negative and/or offensive comments on your site.

However, that can quickly escalate and cause a potential security breach if you don’t take immediate preventive action.

One of the best security practices you can employ is by blocking their IP address. Similar to your home address, an Internet Protocol address is a unique identifier that every machine within a network has.

By blocking a users’ IP address, you sever their line of communication and prevent them from accessing your website.

Blocking Addresses Using IP Manager

There are a couple of methods on how to block an IP address from accessing your site. The easiest way would be to doing so using the IP Manager feature on your Control Panel.

Here’s how it’s done:

  1. Open your Hostinger hPanel, then navigate to the IP Manager section within the Other area.
    IP Manager section in WordPress
  2. In the Block an IP Address box, input the IP address you want to block in the IP to Deny textbox and additional comments on the Notes textbox. Once you’re done, click Add.Block an IP Address feature
  3. To undo this process, do the same action on the Allow an IP Address area.
  4. If the process is successful, a confirmation message should appear on your screen.Confirmation of successful process

Congratulations! You have blocked access to the user from that particular IP address. To prevent several IP addresses from accessing your site, you can repeat these steps as many times as necessary.

Blocking an IP Address Using .htaccess

Another way to block an IP address is by using .htaccess which is a file you can access if you’re running Apache as your web server (Hostinger uses Apache). By denying an IP address’ access in Apache web server’s configuration file, the banning process can be executed before your site is fully loaded.

Here’s how to do it through your .htaccess file:

  1. Open your Hostinger hPanel, then navigate to the File Manager section within the Files area.File Manager section in hPanel
  2. Open your .htaccess file in your public_html directory by clicking on the file then use the Edit feature on the toolbar.public_html directoryYou can also do so by connecting your account via FTP client (see this article for more information regarding this method).
  3. Once the Edit File page is opened, insert this following lines above the existing code
    Order Deny, Allow
    Deny from 127.0.0.1

    .htaccess additonal code

Make sure you create a backup copy of the original code in the case of failure. Once you’re done, click Save & Close.

That’s all! Pretty easy and straightforward, right?

Geo-Blocking with .htaccess

There are cases where the attacks come from a certain country. Or, you probably don’t want your content to be accessible in some countries for specific reasons. To solve this scenario, you can deny access from a particular country using the .htaccess file.

  1. Open your .htaccess file in your public_html directory. Leave it open for now.
  2. Generate a list of IP addresses from the country of your choice on this site. To do so, click on the country name, then set the format to Apache .htaccess Deny. Once you’re done, click Create ACL.Generate a list of IP addresses using Country IP Blocks
  3. Copy the code within the generated list to your .htaccess file, then click Save & Close.
  4. Now your site is accessible for users across the world except the ones residing in the country you have denied access to.

Conclusion

Blocking an IP address is one of the best ways to protect your website from malicious attacks. Contrary to popular belief, it can be easily done using the IP Manager and the .htaccess file.

To block an IP address using IP Manager, you need to:

  1. Open IP Manager on hPanel
  2. Input the targeted IP address in the Block an IP Address section

If you choose to use .htaccess file instead, you need to:

  1. Open the File Manager section on hPanel
  2. Open your .htaccess file in the public_html directory using the Edit feature
  3. Add the syntax containing the targeted IP address along with its access permission

You can also block access to your site from a certain country using .htaccess file:

  1. Open your .htaccess file in the public_html directory using the Edit feature
  2. Generate a list of IP addresses from the targeted country on Country IP Blocks site
  3. Copy the code from the generated list to the .htaccess file

Using these methods, your site will be a safe place for everyone, especially you.

About the author

Jordana Alexandrea

Jordana is Hostinger's Digital Content Writer. She is passionate about content creation, SEO writing, and the growth of information systems. During her free time, she dabbles in freestyle writing and the latest gaming news.

Add Comment

Click here to post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Get Exclusive Content

Join thousands of webmasters who get our free newsletter with tips on how to drive more traffic and revenue to their websites!

Please wait...

Thank you for sign up!

More in WordPress Tutorial
10 Best WordPress Affiliate Plugins for 2019
Close