Block an IP address from accessing your website
An IP address is a unique set of numbers assigned to devices to identify them on a network or the internet.
⚠️ IP address blocks are set per domain, which means if you have multiple websites and want to apply the same IP address block(s) on all of them, you will have to implement the block(s) on each website .htaccess file.
Activate IP address blocks
You can block a single IP address or an IP address range from accessing your website by adding a snippet to your website .htaccess file. Your .htaccess file is located on your hosting control panel.
1. Open and follow this guide to access the .htaccess file of your website: Manage and edit .htaccess file
2. In your website .htaccess file, use the snippet formats below to create a block for a single IP address, IP address range, or to block the IP addresses from an entire country.
⚠️ Important:
- Each .htaccess file has distinct and varied content
- Place your IP address block snippet at the top of the .htaccess file
- If the top section is full, press ‘Enter’ or ‘Return’ within the file to create space, shifting other snippets downward
- The IP address block snippet needs to be on a separate line to function properly
Block a single IP address
- To block a single IP address:
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 a visual example of how that snippet will look inside the skystrahelp.com .htaccess file:
Block an IP address range
- To block an IP address range, as an example, to block all IP addresses from 123.123.123.1 to 123.123.123.255:
Deny from 123.123.123
⚠️ The IP range 123.123.123 is only an example, make sure to replace it with the IP range you want to block.
Below is a visual example of how that snippet will look inside the skystrahelp.com .htaccess file:
3. Once your snippet is in place, click the Save File button in the .htaccess file to activate the IP address block
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 the 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. Open and follow this guide to access the .htaccess file of your website: Manage and edit .htaccess file
12. In your website .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 the skystrahelp.com .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.
View IP address activity
To get a log of IP address activity on a specific domain name, use the 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-hand side of the log, you will see each IP address accessing your website along with a timestamp. To get the latest activity, scroll to the bottom of the log. This log is dynamic and updates in real-time.