The safety and integrity of a website are one of the top-most priorities of a business or a company. Limiting access by IP address is extremely useful in ensuring no unauthorized person gains access even by mistake. This safety measure also serves to limit malicious attacks on websites, prevent people from continuously posting derogatory comments, and is also helpful in denying access to employees who have been let go. Overall, restricting entry by IP address ensures that everyone is not given free rein to wander about your website and leave behind the carnage in the form of stolen data or viruses galore.

The other aspect of limiting access is that it makes for more effective and efficient geotargeting. It helps weed out the traffic from locations where your business does not serve. So what you get in the end is footprints from those audiences that are most likely to convert. You get meaningful traffic, and the integrity of the site remains intact.

Is There A Downside To Restricting Website Access By IP Address?

The drawbacks or downsides to restricting access to a website by IP address are:

  • The burden of work on the server increases as it has to monitor every IP address that tries to engage with the website hosted on it. But this disadvantage is a small price to pay considering the gains it helps to make.
  • Many times legitimate users use proxies out of sheer caution. In fact, it is becoming more common for a large population to operate this way, and there’s nothing wrong with hiding behind a VPN. But what you deem as traffic from an unfriendly location may turn out to be potential leads from friendly ones.

How To Restrict Access To Website By IP Address

There are three main ways in which a company or an individual can limit the people visiting their website. These are:

  1. Restricting access using IP Geolocation tools
  2. Restricting access using .htaccess
  3. Restricting access using cPanel

1. Restricting Access Using IP Geolocation Tools

Geo restriction is often referred to as geo-blocking or geolocation blocking. It lets the site administrator choose the countries where they want to deliver and restrict their content. This is done by preparing either a whitelist (access allowed) or a blacklist (access denied) of countries.

IP Geolocation API and database are the prominent IP geolocation tools that help you restrict your web pages to users from specific countries or locations. IP geolocation tools should be your primary choice, whether it’s in the interest of location-based marketing, countering the threat of phishing attacks, adhering to licensing and copyright agreements, or anything else of your choosing.

2. Restricting Access Using .htaccess

If you wish to make the access permission changes using set rules for a range of IP addresses, you can do so with .htaccess. “.htaccess” is a directory-level configuration file. It is supported by many web servers and used for configuration of website-access issues, like URL shortening and redirection, access control (allowing and forbidding access), etc.

  • You begin by creating a .htaccess file in the public_html folder.
  • Then, you add your preference.

The Allow and Deny commands let one give permission and deny access based on the hostname of the visitor’s server or the IP address.

Furthermore, one can combine “Allow” and “Deny” commands in one place using “Order.” These are the two possible ways to proceed:

Alternative 1 – Block or Allow Specific IP Addresses

Order Allow, Deny

Deny from 121.121.121.121

Allow from all

In this example, only the IP address 121.121,121,121 is forbidden access, and the rest are allowed.

If you wish to block more than one IP address, in that case, the string would be:

Order Allow, Deny

Deny from 122.122.122.122

Deny from 182.182.182.182

Alternative 2 – Block or Allow A Range of IP Addresses

Order Allow, Deny

Deny from 121.121.121.0/18 

Allow from all

One can set rules for a complete range or subnets of IP addresses. As shown above, it is achieved by setting “from-to” values in the IP address.

And by using “*,” you can achieve the same for complete sets or groups, like:

Order Allow, Deny

Deny from 121.121.*.*

Allow from all

3. Restricting Access Using cPanel 

It is possible to manage access control with the help of IP Deny Manager in the cPanel. The cPanel gives the site administrator the power to stop specific IP addresses from seeing and accessing your website. These are the steps you need to follow:

  • Login to your website’s cPanel.
  • Go to the “Security” tab, and click on the icon for “IP Blocker.” You can input a wide range of IP formats, like:
  • Single IP Address – 103.64.566.216 (will deny access to only the given IP address). 
  • Implied Range – 103.64.566.21 – 103.64.566.33 (this will block all those IP addresses that fall between the given parameters).
  • CIDR (Classless Inter-Domain Routing) Format – If you want to block IPs in the range 10.3.3 using CIDR, for example, /24 will block 10.3.3.0-255, /16 will block 10.3.0.0 to 10.3.255.255.
  • Implied IP Address – 103. Implies 103.*.*.* (Blocks all IPs that start with 103).
  • Now you enter the IP address you wish to prohibit and click the “Add” button.
  • You will now be directed to the success page, and that’s all it takes.

Once these steps are completed, you will see the prohibited IP address in the blocked list. The IPs on the list will not be allowed to enter and access your site. If these addresses visit the website, they will see the 403 error.

Bottomline

There are many ways to restrict access to a website, but what matters is which one makes the site administrator comfortable. Today, most people opt for geo-blocking because it is a direct way of blocking users from a country where you don’t want to display your content or probably show it in a different language. Hopefully, this post will have given you a fair idea of getting started. Once you begin, things will become much more transparent and more manageable. Good luck, and get cracking!