How To Block An IP Or An Internet Site Using PowerShell In Windows 10

PowerShell comes with a Netsecurity module that permits you to configure the Windows Firewall. you'll use the function — New-NetFirewallRule — in Netsecurity to dam an IP or an internet site using PowerShell in Windows. The feature allows you to make a replacement inbound or outbound firewall rule and adds the rule to the target computer.

Block IP Or Website Using PowerShell


How To Block An IP Or An Internet Site Using PowerShell In Windows 10

While blocking IP ranges work perfectly, blocking an internet site or domain is hard . That’s because there are often a multiple IP attached to the domain, and while you'll prevent them, the DNS resolver can find out a special IP whenever it queries. Also, at times, an equivalent IP might be employed by related services, and blocking that IP would mean blocking other services also .

1. Block local or internet IP addresses
2. Block website or domain names

You will need admin privileges to execute these.

1] Block IP or Range using PowerShell


How To Block An IP Or An Internet Site Using PowerShell In Windows 10

Using this command, you'll use one IP address or range of IP addresses. Execute the subsequent command in PowerShell.

New-NetFirewallRule -DisplayName "Block XYZ.com IP address" -Direction Outbound –LocalPort Any -Protocol TCP -Action Block -RemoteAddress 146.185.220.0/23

You can replace Block XYZ.com IP address with anything you'll remember or makes it easy to know whenever you reminisce at it. The IP address mentioned at the top of the RemoteAddress option is what is going to be blocked. Any website or service that resolves thereto are going to be blocked. You'll replace the RemoteAddress option with the LocalAddress option if the IP is that the local network IP address.

How To Block An IP Or An Internet Site Using PowerShell In Windows 10

Once the execution is complete, you ought to receive a standing message as ” The rule was parsed successfully from the store. (65536).” Open Windows Firewall and check if the entry is out there. Once confirmed, you ought to be ready to add more using PowerShell.

2] Block Website or Domain using PowerShell


How To Block An IP Or An Internet Site Using PowerShell In Windows 10

Since the function doesn’t support URL blocking, we've two choices. First is to question all possible IP of that domain, and block them. The second is to seek out known official IP ranges and block them. The later has lower chances of accidentally blocking other services compared to the previous. That said, if blocking a website is important, you'll always use another software to dam them.

Resolve-DnsName "facebook.com"

Note the IP address which we'll use within the second method

New-NetFirewallRule -DisplayName "Block XYZ.com IP address" -Direction Outbound –LocalPort Any -Protocol TCP -Action Block -RemoteAddress 146.185.220.0/23

When I used this with YouTube, it didn't work though direct IP was blocked. Once I had used it, with Facebook, it worked. So if an internet site are often resolved using the multiple IP addresses, then this method won't work.

Using PowerShell commands are straightforward. If you ever used the prompt, it's nearly as good as that; I hope you were ready to block IP or an internet site using PowerShell in Windows successfully. Anytime, you would like to get rid of them, you'll do so from Windows Firewall or use the Remove-NetFirewallRule command.
"Allah Ta'aalaa lebih menyukai pelaku maksiat yang bertobat dibanding orang sholeh yang dirinya tidak pernah merasa salah." ─ UAH

Post a Comment