Whitelisting an IP address usually means one of two different things: either you want to restrict a site, folder or admin area so only certain IP addresses can reach it, or you need to unblock a visitor's IP address that your server's security software has blocked by mistake. The steps below cover both situations.
Restricting a folder to specific IP addresses
This method works with LiteSpeed Web Server on any hosting plan, and is done by editing a file called .htaccess. Put the code in the root folder of your site to protect the whole site, or in the /wp-admin/ folder to protect only the WordPress admin area.
cPanel
- Log in to cPanel and open File Manager.
- Navigate to
public_html(or the subfolder you want to protect, such aspublic_html/wp-admin). - Find the file named
.htaccess. If it is not visible, turn on "Show Hidden Files" in the File Manager settings. - Right-click the file and choose Edit.
- Add the following lines at the top of the file, replacing the example IP address with the one you want to allow:
<RequireAny>
Require ip 203.0.113.10
</RequireAny>
- Add one
Require ipline for each extra IP address you want to allow. - Save the file, then test access from an allowed and a non-allowed connection.
DirectAdmin
- Log in to DirectAdmin and open File Manager.
- Go to the
public_htmlfolder, or the subfolder you want to restrict. - Open the
.htaccessfile for editing, creating it if it does not already exist. - Add the same
Require ipblock shown above, listing each IP address you want to allow. - Click Save and test the folder from both an allowed and a blocked connection.
Unblocking an IP flagged by security software
If a legitimate visitor, or you, cannot reach the site because of a firewall block, the fix is to remove that IP address from the block list rather than edit .htaccess. Hostking servers use Imunify360 to automatically block IP addresses that trigger too many failed logins or suspicious requests.
cPanel
- Log in to cPanel and open the Imunify360 or Security section.
- Choose the option to view blocked or banned IP addresses.
- Find the IP address that needs access and select Unblock or Whitelist.
- Confirm the change and ask the affected visitor to try again after a few minutes.
DirectAdmin
- Log in to DirectAdmin and look for the Imunify360 or firewall section.
- Open the list of currently blocked IP addresses.
- Select the relevant IP address and choose to unblock or whitelist it.
- Save the change and confirm the visitor can reach the site again.
If you cannot find an Imunify360 or security option in your control panel, check your welcome email or the client area for the exact menu name on your plan, or ask support to check the block list for you.
Troubleshooting
- Still blocked after whitelisting: your device may have a different public IP address than expected, especially on mobile data or a changing home connection; check your current IP address again before adding it.
- .htaccess changes have no effect: make sure the file was saved in the correct folder and that there is no second
.htaccessfile overriding it further down the folder structure. - Locked out of your own site after editing .htaccess: connect via File Manager or FTP using your hosting login (not the restricted URL) and remove or correct the
Require iplines. - IP keeps getting blocked again: this usually means repeated failed login attempts are still happening, often from a saved password or bot traffic, so check for login attempts after unblocking.
If you are still stuck, contact Hostking support through live chat on the website or by opening a support ticket from the client area.
