Block an IP address, IP address range, or entire country from accessing your website
Definitions
IP address: An IP address is a unique numerical identifier assigned to each device connected to a network, enabling it to communicate with other devices.
IP address range: An IP address range is a sequence of consecutive IP addresses, typically used to define a specific network or segment within a larger network.
Before you start
✅ There are typically three types of IP address blocks:
- Single: To block one IP address.
- Range: To block a grouped set of IP addresses.
- Country: To block the IP addresses from an entire country.
ℹ️ IP address blocks are set for each domain, so if you have multiple websites or apps, you need to apply the same IP address block(s) in the .htaccess file of each domain.
⚠️ IP blocks should be a last-resort security measure because they can degrade website performance and may block legitimate users.
⚙️ If you are trying to get a log of IP address activity on a specific domain name before applying blocks, use the quick steps below.
1. Log in to your hosting control panel
2. Click on the Stats / Error Logs button

3. Find your domain name and click on Usage Log

4. On the left side of the log, you’ll see each IP address accessing your website with a timestamp in EST (Eastern Standard Time). For the latest activity, scroll to the bottom. The log updates in real-time.

Step by step
1. Go to your domain .htaccess file, use this guide for steps: Access and modify your .htaccess file
2. In your domain .htaccess file, use the steps below to create a block for a single IP address, IP address range, or to block the IP addresses from an entire country.
⚠️ Read these points before you start modifying your .htaccess file:
- ➡️ Each .htaccess file has distinct and varied existing code snippets, this is normal.
- ➡️ Put your IP address block snippet(s) at the top of your .htaccess file. If there’s no room at the top, press ‘Enter’ or ‘Return’ on your keyboard to create space by moving the existing snippets down.
- ➡️ IP address block snippet(s) need to be on their own separate line to function properly.
- ➡️ You need to click the Save File button at the top right of your .htaccess file to apply changes.
Block a single IP address
- In your .htaccess file, put in the following snippet:
Deny from 123.123.123.123
ℹ️ The IP Address 123.123.123.123 is only an example, make sure to replace it with the IP address you want to block. Below is an example of how the snippet looks inside our .htaccess file:

Block an IP address range
- In your .htaccess file, put in the following snippet:
Deny from 123.123.123
ℹ️ The IP range 123.123.123 is only an example. In this example, all IP addresses from 123.123.123.1 to 123.123.123.255 would be blocked. Make sure to replace it with the IP range you want to block. Below is an example of how the snippet looks in our .htaccess file:

Block an entire country
To block an entire country from accessing your website, follow the steps below.
1. Go to this website: IP2Location Block Visitors by Country
2. Scroll to the Download List section

3. On the Country dropdown, select the country you want to block. In our example, we will select China.
4. On the IP Version dropdown, select IPv4
5. On the Output Format, select Apache 2.0 – 2.3 .htaccess deny
6. Click the Download button to download the file to your device

7. On your device, find the downloaded file called firewall.txt.gz (normally in your Downloads folder or Desktop)

8. Click on the firewall.txt.gz folder to extract it. Once extracted, you will see a firewall.txt file, click to open it.

9. Once the firewall.txt file is open, at the top, find the first line item that says deny from click to the left of it, and drag your mouse to the bottom of the file until the last deny from line item, right above where it says </Limit>


10. Right-click your mouse and select Copy to copy all of the IP addresses to your clipboard

11. Go to your domain .htaccess file. If you don’t remember how, use this guide for steps: Access and modify your .htaccess file
12. In your domain .htaccess file, paste in all of the deny from IP addresses into your .htaccess file. Below is a visual example of how that full list would look inside our .htaccess file:

13. Once the full deny from IP address list is in place, click the Save File button in the .htaccess file to activate the country block. Once saved, the entire country you’ve selected will be blocked from accessing your website.
