Controlling access to your website based on IP addresses is an effective way to secure your site, block malicious users, or restrict access to specific areas. Using OzSpeed’s hPanel, you can easily allow or block specific IP addresses by modifying the .htaccess
file or using hPanel’s built-in IP Manager. Here’s a step-by-step guide on how to set it up.
Method 1: Block or Allow IP Addresses Using hPanel’s IP Manager #
OzSpeed’s IP Manager feature in hPanel offers a simple interface for managing IP address restrictions without the need to edit configuration files manually.
Step 1: Log in to hPanel #
- Go to ozspeed.com.au and log in to your hPanel Dashboard.
- Navigate to Advanced and click on “IP Manager”.
Step 2: Block an IP Address #
- Click on “Add IP to Block”.
- Enter the IP address you want to block (e.g.,
192.168.1.1
). - Click “Block IP”.
Tip: #
- You can block an entire range of IP addresses by using a wildcard (e.g.,
192.168.1.*
) or a CIDR notation (e.g.,192.168.1.0/24
).
Step 3: Allow an IP Address #
- Click on “Add IP to Allow”.
- Enter the IP address you want to allow (e.g.,
203.0.113.5
). - Click “Allow IP”.
Tip: #
- Use the allow list cautiously, as it can override other restrictions set up on your website.
Step 4: Save and Test #
- Click “Save Changes” to apply the settings.
- Test the access by visiting your website from the allowed or blocked IP address.
Method 2: Block or Allow IP Addresses Using .htaccess
#
You can also manage IP restrictions manually by editing the .htaccess
file in your website’s root directory.
Step 1: Edit the .htaccess
File #
- Go to Files > File Manager in hPanel.
- Navigate to the public_html directory.
- Open the
.htaccess
file for editing or create a new one if it doesn’t exist.
Step 2: Block Specific IP Addresses #
Add the following code to your .htaccess
file to block one or more IP addresses:
apacheCopy code<Limit GET POST>
Order Allow,Deny
Deny from 192.168.1.1
Deny from 203.0.113.10
Allow from all
</Limit>
Explanation: #
- Deny from: Blocks access for the specified IP addresses.
- Allow from all: Ensures that all other IPs are allowed unless specifically blocked.
Step 3: Allow Only Specific IP Addresses #
If you want to restrict access to specific IP addresses, use this code:
apacheCopy code<Limit GET POST>
Order Deny,Allow
Allow from 203.0.113.5
Deny from all
</Limit>
Explanation: #
- Allow from: Grants access only to the specified IP addresses.
- Deny from all: Blocks all other IP addresses by default.
Step 4: Block an IP Address Range #
To block an entire range of IP addresses, use wildcard characters or CIDR notation:
apacheCopy code<Limit GET POST>
Deny from 192.168.1.*
Deny from 203.0.113.0/24
Allow from all
</Limit>
Tip: #
- Use CIDR notation for more precise control over IP ranges (e.g.,
/24
blocks 256 addresses).
Step 5: Save and Test #
- Click “Save” to apply the changes.
- Visit your website from the restricted IP address to ensure the rule is working.
Method 3: Block IP Addresses Using Firewall Rules #
If you’re using a Content Delivery Network (CDN) like Cloudflare or a firewall service, you can manage IP restrictions directly through their dashboard.
How to Set Up Firewall Rules: #
- Log in to your CDN or firewall provider’s dashboard (e.g., Cloudflare).
- Go to the Firewall Rules section.
- Click “Create a Firewall Rule”.
- Set the rule to Block specific IP addresses or ranges (e.g.,
192.168.1.1
or203.0.113.0/24
). - Save the rule and test access.
Tip: #
- Using a CDN for IP blocking is effective because it filters traffic before it reaches your server.
Troubleshooting Tips #
- Blocked Access Despite Whitelisting:
- Clear your browser cache or try accessing the site in Incognito mode.
- Ensure there are no conflicting rules in multiple
.htaccess
files.
- IP Not Blocked:
- Verify the IP address using an IP lookup tool. The visitor’s IP may be different if they are using a proxy or VPN.
- Check for any caching issues or CDN rules that might override your
.htaccess
settings.
- 403 Forbidden Error:
- This error typically occurs if access is denied. Double-check your
.htaccess
rules and ensure there are no syntax errors.
- This error typically occurs if access is denied. Double-check your
- Testing IP Restrictions:
- Use a VPN or proxy service to test access from different IP addresses.
- Check the Access Logs in hPanel’s Logs section to verify if the IP addresses are being blocked correctly.
Additional Tips: #
- Rotate IP Allow List Regularly: If you use a dynamic IP, update the allow list when your IP changes.
- Use CIDR Notation for Large IP Ranges: CIDR notation (e.g.,
/24
) is efficient for blocking multiple IPs. - Monitor Access Logs: Regularly review your website’s access logs to identify suspicious IP addresses for blocking.