How to Restrict Access to a Site by IP Address in IIS
In this article9 sections
Some pages should only be seen by your own team: an admin area, a staging site, a reporting dashboard, or a tool that exposes internal data. On IIS, you can limit a site or a folder to a list of IP addresses, so every other visitor gets a 403 Forbidden response. This guide shows how to set up the IP restriction feature, how to limit one folder without affecting the rest of the site, and how to avoid the common mistake of locking yourself out.
IP restriction is a useful layer, not a complete defence. It is most effective for an admin area or a staging site, and it sits alongside a strong password and, where you can, two-factor sign-in. On Siteharbour’s Windows hosting, the feature is part of IIS, and the steps below apply to any IIS site.
Before you start
- The public IP address you will connect from. Find it by searching for “what is my IP” in a browser on the network you use. An office with a fixed address is the easiest case. A home connection can change its address, which needs a different plan.
- The IP Address and Domain Restrictions role service, installed on the server. Ask your host to confirm it if the option is missing.
- A copy of
web.config, because a broken file stops the whole site.
Step 1: Confirm the feature is installed
In Server Manager, under the web server role, check that IP and Domain Restrictions is listed as installed. If it is missing, the rules in Step 2 do nothing, and the site stays open to everyone.
Expected: the role service shows as installed. Your host can add it in a few minutes if it is not.
Step 2: Add your address to the allowed list
Open web.config for the site and add an ipSecurity element inside system.webServer. Set allowUnlisted to false, so only the addresses you list can connect, and add your own address first:
<security>
<ipSecurity allowUnlisted="false">
<add ipAddress="203.0.113.25" allowed="true" />
</ipSecurity>
</security>
On a shared server, the ipSecurity section may be locked at server level, so a site’s own web.config is not allowed to change it. If the site returns a 500.19 error after you add the block, remove it and ask your host whether the section can be unlocked for your site, or use the IP access options in your hosting panel instead.
Replace 203.0.113.25 with your own public address. Add one add line for each address that should have access. A range can be written with a subnet mask in the subnetMask attribute, but for a small team a list of single addresses is easier to check.
Step 3: Restrict one folder, not the whole site
Often only one folder needs protection, such as /admin. Put the restriction in a web.config file inside that folder, so the rest of the site stays open. The file uses the same security element as in Step 2. The rules apply to requests in that folder and below it.
Expected: a request to the folder from an unlisted address returns 403 Forbidden, and the rest of the site loads as before. Test both cases, because a rule in the wrong folder protects nothing.
Step 4: Test from an allowed and an unlisted address
From your listed address, load the protected folder in a browser. Expected: the page loads. From another network, such as a phone on mobile data, load the same address. Expected: a 403 Forbidden page. You can also test from a terminal, which shows the status code directly:
curl -sI https://example.com/admin/ | head -n 1
Expected: HTTP/2 403 from an unlisted address, and HTTP/2 200 or a redirect to the login page from a listed one.
Step 5: Avoid locking yourself out
The most common mistake is restricting a site to an address that changes. A home connection, a mobile network or a VPN can give you a new address on the next connection. Before you save the rule, keep a second way in: an open connection, a second listed address, or a host support contact who can remove the rule. Then test from the network you use every day.
If you do lock yourself out, the fix is to remove the rule, which you can do over the file manager or by SFTP, since the rule lives in the file. Keep the SFTP login ready before you change the rule.
Step 6: Keep the list current
Review the allowed addresses when a team member leaves or changes network, and remove addresses you no longer need. An old address on the list is an entry point for someone who gets that address later. Write the list down in your password manager’s notes or in a document the team can see, so the next person knows why each address is there.
Common mistakes
- Forgetting the role service. The rules do nothing without it, and the site looks protected when it is not.
- Restricting the whole site when one folder needs it. Public pages then return 403 too.
- Using a dynamic home address. You lose access when it changes.
- Trusting the IP alone. An address can be shared or spoofed behind a proxy. Keep a strong password on the protected area.
- Breaking web.config. Keep a copy, and test after each change.
Frequently asked questions
Does IP restriction replace a password?
No. Use both. The address stops most visitors, and the password stops anyone who is on an allowed address.
Can I restrict by country?
Not with this feature alone. It works on addresses, and a country list needs a service that maps addresses to locations.
Why does a proxy or CDN break the rule?
The server sees the proxy’s address, not the visitor’s. Use the forwarded address rule for the proxy, and only if the proxy is trusted.
What status does a blocked visitor see?
A 403 Forbidden page. You can replace it with a custom page in IIS, but the status code stays 403.
IP restriction on IIS is a rule in web.config that allows only the addresses you list. Confirm the role service is installed, restrict one folder rather than the whole site, test from a listed and an unlisted network, and keep a second way in before you save. Pair it with a strong password, and review the list when people or networks change. For the public side of a Windows site, read how to redirect HTTP to HTTPS on IIS.