• About Us
  • Privacy
  • Terms
    • DMCA
  • AdChoices
  • Contact Us
  • Careers
  • Dictionary
  • Donate
No Result
View All Result
Nyongesa Sande
  • Radio
  • Events
  • How To
  • AI
  • Business
    • Shop
    • Money
    • Billionaires
  • Finance
  • Gadgets
  • Lifestyle
  • Sports
  • Autos
Nyongesa Sande
No Result
View All Result
  • Radio
  • Events
  • How To
  • AI
  • Business
  • Finance
  • Gadgets
  • Lifestyle
  • Sports
  • Autos

Home » How to block an IP address from accessing your website

How to block an IP address from accessing your website

November 19, 2023
in How To
Reading Time: 5 mins read
A A
FacebookXTelegramWhatsappLinkedIn

If you are experiencing repeated attempts to hack your site, or you wish to prevent access to your site for other reasons, you have two methods to choose from to block IP addresses. Both allow you to block computers using specific IP addresses, or devices from a range of addresses, from accessing your website.

ADVERTISEMENT

Block access with the cPanel IP Blocker

Your HostPapa Dashboard is equipped with a feature called the cPanel IP Blocker. Head to My cPanel in your HostPapa Dashboard and head to the Security section.

IP Blocker provides less flexibility than other methods but is easier to use. For example, you can block access to your website by IP address, IP address range or domain name, but you cannot target specific files or file types like you can with the second method we’ll walk through – using .htaccess rules.

In the Add an IP or Range field, enter the IP address, IP address range or domain for which you wish to block access and click Add.

ADVERTISEMENT

Deny access from IP addresses through cPanel IP Blocker

You can specify IP addresses in the following formats:

  • Single IP Address: 192.168.0.1
  • Range: 192.168.0.1-192.168.0.40
  • Implied Range: 192.168.0.1-40
  • CIDR Format: 192.168.0.1/32
  • IP Block: 192

IP Blocker checks the validity of the IP address format as you type. Enter the IP address or range and click Add.

Deny access from specific domains through cPanel IP Blocker

To block traffic linking to your website from a particular domain, enter the domain name in the  Add an IP or Range field.

cPanel will reconcile the domain name with its IP address via a lookup. If the IP address cannot be found, you will not be able to block the domain.

Manage blocked IP addresses and domains through cPanel IP Blocker

At the bottom of the IP Blocker page, you’ll see a section called Currently-Blocked IP Addresses. This provides a list of IP addresses that are currently blocked from accessing your server. To lift access restrictions, use the Delete button next to each IP address or range.

Restrict access to your website using a .htaccess file

.htaccess is a configuration file used by the Apache webserver. .htaccess rules override global settings for the directory in which the file is placed. You may find that .htaccess files are created automatically on your server when installing popular web applications like WordPress, Drupal and Magento. However, if one does not exist, it can be easily created in a text editor and uploaded to your server. You can also create one directly from cPanel’s File Manager.

To get started, log in to your HostPapa Dashboard.

ADVERTISEMENT

In the top navigation menu, select My cPanel.

Now select File Manager.

At the top right of the screen, click the Settings button.

.htaccess files are hidden from view by default. To expose them, ensure Show Hidden Files (dotfiles) is checked in the Preferences panel, then click Save.

Navigate to your website root using the left sidebar. Check to see whether a .htaccess file currently exists.

If the .htaccess file exists, highlight it and select Edit from the top menu.

Alternatively, you can create a new .htaccess file by selecting + File.

In the New File panel that opens, enter .htaccess as the file name and select Create New File to open the cPanel text editor. If you are asked to confirm Encoding settings, leave the default option in place and click Edit.

You can now create the rules required to restrict access to your website. These rules can be configured to block all users or specific users (based on their IP address) from accessing website resources. You can also deny access to certain file types, specific files (for example, configuration files) and more.

Deny access to all files and folders through .htaccess

To prevent direct access to all files and folders on your server, create the .htaccess file in the root (top folder) of your server and add the following rule:

deny from all

Deny access to specific file types through .htaccess

If you wish to deny access to certain types of files, you can do so with the following rule. This example blocks access to .php files.<Files ~ “\.php$”> Order allow,deny Deny from all </Files>

Simply change the file extension in the first line of the rule for other file types. For example, this rule blocks access to .inc files:<Files ~ “\.inc$”> Order allow,deny Deny from all </Files>

Deny access to a specific file through .htaccess

Blocking access to a specific file is performed using the following rule:<Files config.php> order allow,deny Deny from all </Files>

This example targets a config.php file held in the same directory as the .htaccess file. To change the target, replace config.php in the first line with your chosen filename.

Deny access from specific IP addresses through .htaccess

If you wish to block a specific user from accessing your website, you can do so using their IP address or the domain name from which they’re visiting. Use the following htaccess rule (replacing the numbers with the user’s IP address):

deny from 123.456.789.123

To deny access to a block of IP addresses, simply leave off the last octet from the IP address:

123.456.789.

This blocks access to anyone using an IP in the range of 123.456.789.0 to 123.456.789.255.

Deny access from specific domains through .htaccess

Denying access via links from specific domains (e.g. www.problemdomain.com) is also possible through htaccess. The following rule will display a 403 Forbidden error to any user accessing your site from a link hosted on the targeted domain:SetEnvIfNoCase Referer “problemdomain.com” bad_referer Order Allow,Deny Allow from ALL Deny from env=bad_referer

Change the domain in the first line of the rule to target the domain you wish to block. For a subtler approach, this rule displays a 500 Internal Server Error for anyone linking from the target domain:RewriteEngine on RewriteCond %{HTTP_REFERER} example\.com [NC,OR] RewriteRule .* – [F]

Remove access restrictions through .htaccess

If you wish to remove access restrictions held in your .htaccess file, simply delete the rule from the file in cPanel File Manager’s text editor and save the file.

If you need help with your HostPapa account, please open a support ticket from your dashboard.

Was this article helpful?
YesNo
Tags: experiencing repeated attempts to hack your siteHow To
ADVERTISEMENT
Previous Post

How to Fix the WordPress White Screen of Death

Next Post

List of Elected MCAs in Kakamega County 2022-2027

RelatedPosts

How to Add Dependants on SHA Online in 2025: A Step-by-Step Guide
How To

Methods Used to Register for SHA in Kenya

11 months ago

Methods Used to Register for SHA in Kenya The Self-Help Association (SHA) is a popular model in Kenya for promoting...

List of best Business To Business Services in Kenya
How To

How to Secure Sponsorships for Your Business, Project, or Event

2 years ago

This article explains How to Secure Sponsorships for Your Business, Project, or Event Part 1: Finding Potential Sponsors Identify Similar...

Illustration of a newspaper showing an RV image in the travel section, symbolizing road trip or camper news coverage.
How To

How to Find the Value of a Motorhome

2 months ago

Knowing how to find the value of a motorhome is essential before buying or selling an RV. Like cars, motorhomes...

How to Activate Metrash2 through SMS
How To

How to Submit Excise Tax Return in Qatar

2 years ago

How to Submit Excise Tax Return in Qatar. This service allows taxpayers to submit their excise tax return.   Instructions...

How to Activate Metrash2 through SMS
How To

How to Apply to Relocate Portacabin in Compound Farms in Qatar

2 years ago

How to Apply to Relocate Portacabin in Compound Farms in Qatar. A portacabin in a compound typically refers to a...

How to Use the Self-Service Portal to Regain Access to a Computer
How To

How to Upgrade Your PC to Windows 11 for Free

3 years ago

How to Upgrade Your PC to Windows 11 for Free. How much does it cost to upgrade from Windows 10...

How to Apply for Jio Broadband (Jio Fiber) Online
How To

How to Apply for Jio Broadband (Jio Fiber) Online

2 years ago

How to Apply for Jio Broadband (Jio Fiber) Online. Jio broadband service, or Jio Fiber, can be booked online. It...

How to Spot Common Stalking Behavior
How To

How to React if You Think Someone is Stalking You

2 years ago

If you suspect that someone is stalking you, it's essential to take the situation seriously and take steps to protect...

List Of Safaricom Mpesa Loan Products In Kenya
How To

How to get the Safaricom PUK to unlock your Safaricom SIM

12 months ago

When you enter the wrong PIN for your Safaricom SIM more than three times, your SIM card will be locked...

The U.S. Department of Housing and Urban Development (HUD)
How To

How to Contact HUD

1 year ago

The U.S. Department of Housing and Urban Development (HUD) is responsible for national policies and programs related to housing in...

Load More
Next Post
Kakamega County

List of Elected MCAs in Kakamega County 2022-2027

List of Registered Voters in Vihiga County for the 2013 General Elections

List of Elected MCAs in Vihiga County 2022-2027

ADVERTISEMENT
Nyongesa Sande

Nyongesa Sande delivers breaking news, technology updates, billionaire profiles, inventions, AI trends, and inspiring facts.

CC-BY 4.0 Except where otherwise noted, content on this site is licensed under Creative Commons Attribution-Share Alike 4.0 License ; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy.

No Result
View All Result
  • Tech News
  • Banking
  • Biography
  • Politics
  • Presidents
  • How To
  • Wiki
  • Real Estate
  • Health
  • Gadget Reviews
  • Top 10
  • History
  • Companies
  • Sports
  • Loans
  • Finance
  • Travel
  • Breaking News
  • AI
  • Electric Vehicle
  • Motivation
  • Phone Prices
  • Hosting
  • Shopping Malls
  • Africa
  • Business
  • Insurance
  • Restaurants
  • Investment
  • Classifieds
  • KenyanBaze
  • Shop Anything

CC-BY 4.0 Except where otherwise noted, content on this site is licensed under Creative Commons Attribution-Share Alike 4.0 License ; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy.

This website uses cookies. By continuing to use this website you are giving consent to cookies being used. Visit our Privacy and Cookie Policy.