How to Block IP Address in Website?

Are you being attempted hacked by a specific person? Or do you want to block someone from visiting your website? This is where you will see the need to figure out how to block IP addresses. You can block a specific IP address from accessing your website as a website owner. From this article, we are looking forward to sharing the steps on how you can do it. Then you can follow the steps and get the job done.

 

Why Block an IP Address?

why block an ip

Before learning how to block an IP address, you should know why you need to block an IP address. In this section, we will share why you would come across the need to block an IP address.

– Hackers, spammers, and bots

All website owners must deal with the hassle of hackers, spammers, and bots. If you want to overcome their threats, the best thing that you can do is to go ahead and block their IP addresses. Hacking attempts can strain your website bandwidth. On the other hand, it can significantly reduce the access speeds of other visitors to the website. This can eventually create an impact on your search engine rankings and sales. Hence, you should block their IP addresses and keep them away from negatively impacting your business.

for more information on how to securing a domain name read our article.

– Limiting access to the website

limit access

Depending on the content you have on your website and persona preferences, you will come across the need to limit access to your website as well. This is another reason why you need to block IP addresses. For example, we can see how many employers and universities block IP addresses so that only employees and students can access them. This would help to increase productivity while reducing distractions.

– Maintaining confidentiality

You will also be able to limit access to confidential information by blocking out IP addresses. For example, we can see how numerous companies and academic institutions maintain sensitive records, such as health records and transcripts. Hackers are targeting these details. Therefore, you must identify all threatening IP addresses and add them to the block list. Then you can ensure they are not in a position to visit your website.

– Protecting data

If you block an IP address or a group, you can protect your data quite effectively. We often see how hackers try to infiltrate websites out there to steal data as well as other worthy information available out there. It would be possible to use those data to blackmail a company. Hence, the best thing that you can do is block the IP addresses.

 

 

how to block a country from accessing my website?

There are two steps for doing this work:
  1. Use country block IP tools
  2. use the htaccess file and block IPs
you can find IPs by searching on google.

 

how to block an ip address from your website?

There are two main methods available for blocking an IP address. Continue to read, and we will share those two methods with you. You can determine the best method to follow and block IP addresses from the website.

 

1- in cPanel

block ip in cpanel

Your web host will provide you with access to cPanel. You can use cPanel to restrict access to the website. You will need to access cPanel and then visit the option called Security. Under Security, you can see an icon named IP Blocker.

IP Blocker allows you to block IP addresses from accessing your website. This is a simple and easy thing to do as well. This feature allows you to block a single IP address or even a range of IP addresses. However, it will not be possible for you to block access to a specific file or file type on the website from being accessed. If you want to do that, you should look at the next section, where we share details with you on blocking an IP address with .htaccess rules.

When you are inside an IP blocker, you can add an IP address or a range of IP addresses. Then you will need to define the domain or the IP address range you plan to block out. After that, you may click on the button named Add.

Here is the format on how you should add information.

– If you are blocking a single IP address, you can enter it as – 192.168.1.1
– If you are blocking a range of IP addresses, you can enter them as – 192.168.1.1-192.168.1.8
– You can also enter the implied range as – 192.168.1.1-40
– If you are entering the IP address in CIDR format, you should do it as – 192.168.1.1/32
– If you want to do an IP block – 192 (Then all IP addresses starting from 192) will be blocked

Likewise, you will also be able to block access to traffic from a linking domain. This is where you will need to enter the domain name in the Add an IP or Range field. For example, let’s assume you want to restrict people who visit your website from google.com. Then you will be able to enter google.com in the field. Then you can make sure that no person from google.com will be able to access your website.

 

 

2- via htaccess file

via htaccess

The Apache webserver uses a configuration file called .htaccess. .htaccess rules override global settings for the directory where the file is stored. When you install popular online programs like Drupal, WordPress, or Magento, .htaccess files may be produced automatically on your server. If one does not already exist, one may be made in a text editor & uploaded to your server. You may also make one via the File Manager in cPanel.

For more information on “what does .htaccess do” read our article.

To get started, you will need to go to the hosting dashboard. Then you can get to cPanel. While you are in cPanel, you should click on File Manager. Click on the Settings button, which you can see in your top right-hand corner. By default, the .htaccess file will be hidden. Therefore, you will need to click on the Show Hidden Files option to make it visible. This checkbox is visible under the Preferences panel.

Now you can get to the website’s root using the left-hand sidebar. In there, you can see the .htaccess file. You may now click on the .htaccess file and the Edit button from the top menu. Or else, you will also be able to click on the +File button to edit it. In the editing mode, you will need to add restriction rules. Then you can block IP addresses according to your preferences.

You can add the following command to restrict access to all the files and folders via .htaccess.
Deny from all

If you want to restrict access only to some specific files, you will need to add the following code.

<Files ~ “\.php$”>
Order allow, deny
Deny from all
</Files>

You can also change the file extension within the first line for other types of files. For example, let’s assume you want to restrict access to .inc files. Then you should enter,

<Files ~ “\.inc$”>
Order allow,deny
Deny from all
</Files>

In case you want to restrict access only to a specific file, you can add the following code.

<Files config.php>
order allow,deny
Deny from all
</Files>

You should add the following code if you want to deny access from a specific IP address.

Deny from 123.456.789.123

How to unblock the IP address?

unblock ip address

If you blocked access from the .htaccess file, you must delete the restriction code to regain access. If you used an IP blocker, you could follow these steps. A section named Currently-Blocked IP Addresses may be found at the bottom of an IP Blocker page. This displays a list of IP addresses presently unable to connect to your server. Use the Delete button beside each IP address/range to remove access restrictions.

 

 

Final words

Now you know how to restrict access from IP addresses to your website. You can play around with these options and restrict access to the website according to your specific preferences.


<

Leave a Comment