How to Add IP Address to Windows Firewall Rules
In this article
You can restrict or allow network traffic from specific devices by adding their IP addresses to Windows Defender Firewall rules. This is achieved by creating a new inbound or outbound rule that targets a specific remote IP address, ensuring only trusted sources can communicate with your PC while blocking others.
What You'll Need
- A Windows PC running Windows 10 or Windows 11
- Administrator privileges on the computer
- The specific IPv4 address you wish to allow or block
- Access to the "Windows Security" or "Control Panel" settings
Step-by-Step
- Open Advanced Security Settings: Press the
Windows Key + Rto open the Run dialog. Typewf.mscand press Enter. This opens the "Windows Defender Firewall with Advanced Security" window directly, which is more precise than navigating through the main Control Panel menus. Note that menu labels may vary slightly depending on your Windows version. - Select Inbound Rules: In the left-hand pane of the window, click on Inbound Rules. This section controls incoming connections to your PC. If you want to control outgoing traffic from your PC to other devices, select Outbound Rules instead. For most security hardening tasks, Inbound Rules are the primary focus.
- Create a New Rule: In the right-hand Actions pane, click New Rule.... A wizard will appear. Select Custom as the rule type and click Next. Custom rules give you the granular control needed to specify exact IP addresses.
- Specify Programs (Optional): On the Program page, you can choose to apply this rule to all programs or a specific executable. To apply it broadly, leave the default selection (All programs) and click Next. If you only want to allow this IP for a specific app (like a game server or database), click This program and browse to the .exe file.
- Define Protocol and Ports: Keep the default selections (Any for protocol and port) unless you know specifically which port needs access (e.g., Port 80 for web traffic). Click Next to proceed.
- Scope the IP Address: This is the critical step. Under the Scope tab, look for the Remote IP addresses section. Select These IP addresses. Click the Add... button. In the dialog box, enter the specific IPv4 address (e.g., 192.168.1.50) or a subnet range (e.g., 192.168.1.0/24). Click OK, then click Next.
- Action Selection: Choose whether to Allow the connection, Allow the connection if secure, or Block the connection. To whitelist a trusted device, select Allow. To blacklist an attacker or unwanted device, select Block. Click Next.
- Profile Selection: Check the network types where this rule applies: Domain, Private, and Public. It is generally safest to apply these rules to Private and Domain networks. Be cautious applying strict block rules to Public networks if you are in a coffee shop or airport, as it might disrupt connectivity. Click Next.
- Name and Finish: Give the rule a descriptive name, such as "Allow Office Printer IP" or "Block Suspicious IP." Add a description if desired. Click Finish to save the rule.
Common Mistakes
One frequent error is confusing Remote IP with Local IP. The scope step defines who is connecting to your computer (Remote), not your own computer's address. Another mistake is applying a "Block" rule without checking the Profile settings, which can inadvertently cut off internet access if applied incorrectly to public profiles. Additionally, users often forget that IPv6 addresses require separate rules; entering an IPv4 address will not affect IPv6 traffic.
Tips
If you need to manage multiple IPs, consider using a subnet mask (CIDR notation) to group them, reducing the number of rules. Always test your rules by attempting to connect from the target device before finalizing. If you are unsure about the IP address format, verify it on the source machine using the command prompt with ipconfig. Remember that firewall rules are processed in order; if a general "Allow All" rule exists above your specific "Block" rule, the block may be ignored.
Troubleshooting
If the rule does not seem to work, first check the rule order. Open the Inbound Rules list and ensure your new rule is positioned correctly relative to other rules. Sometimes, third-party antivirus firewalls override Windows Defender settings; temporarily disable them to test. Verify that the IP address has not changed due to DHCP leasing on the source device. If you accidentally locked yourself out, boot into Safe Mode to edit or delete the rule via wf.msc.
Frequently Asked Questions
Can I add an IP range?
Yes, you can use CIDR notation (e.g., 192.168.1.0/24) in the Remote IP addresses field to define a subnet range rather than a single address.
Does this work on Windows 7?
Yes, the wf.msc interface and the steps described are largely identical in Windows 7, 8, 10, and 11.
Will this block my internet connection?
No, unless you create a rule that blocks all inbound traffic on all ports. Specific IP rules only affect traffic from that specific source.
How do I remove a rule?
Simply find the rule in the Inbound or Outbound Rules list, right-click it, and select Delete.
Why is my rule grayed out?
A grayed-out rule indicates it is disabled. Right-click the rule and select Enable Rule to activate it.
Do I need to restart my PC?
No, firewall rules apply immediately after creation. No reboot is required.