Home How To How to block an IP or a Website using PowerShell in Windows 10

How to block an IP or a Website using PowerShell in Windows 10

by Mohsin Raza
How to block an IP or a Website using PowerShell in Windows 10

PowerShell accompanies a Netsecurity module that allows you to arrange the Windows Firewall. You can use the capacity — New-NetFirewallRule — in Netsecurity to block an IP or a website using PowerShell in Windows. The feature allows you to create another inbound or outbound firewall rule and adds the standard to the target PC.

Block IP or Website using PowerShell

While blocking IP ranges work flawlessly, blocking a website or domain is precarious. That’s because there can be a multiple IP attached to the domain, and while you can forestall them, the DNS resolver can make sense of a different IP each time it questions. Also, at times, the same IP could be used by related administrations, and blocking that IP would mean blocking different administrations as well.

  • Block local or internet IP addresses
  • Block website or domain names
  • You will require admin benefits to execute these.

Block IP or Range using PowerShell

Block IP or Website using PowerShell

Using this command, you can use a single IP address or range of IP addresses. Execute the following 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 can recollect or makes it easy to understand at whatever point you glance back at it. The IP address referenced at the finish of the RemoteAddress choice is what will be blocked. Any website or administration that takes steps that will be blocked. You can replace the RemoteAddress choice with the LocalAddress alternative if the IP is the local network IP address.

Block IP or Range using PowerShell

When the execution is finished, you ought to get a status message as ” The standard was parsed effectively from the store. (65536)”. Open Windows Firewall and check if the passage is available. When affirmed, you ought to have the option to add more using PowerShell.

Block Website or Domain using PowerShell

Block Website or Domain using PowerShell

Since the capacity doesn’t support URL blocking, we have two options. First is to question all conceivable IP of that domain, and block them. The second is to find known official IP ranges and block them. The later has lower chances of accidentally blocking different administrations compared to the former. That said, if blocking a domain is essential, you can always use another software to block them.

Resolve-DnsName “facebook.com”

Note the IP address which we will use in the subsequent method

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

At the point when I used this with YouTube, it didn’t work however coordinate IP was blocked. At the point when I used it with Facebook, it worked. So if a website can be settled using multiple IP addresses, then this method won’t work.

Also see: Chkdsk runs on every boot? Here are some fixes

Using PowerShell commands are straightforward. If you at any point used the command prompt, it is as acceptable as that; I trust you had the option to block IP or a website using PowerShell in Windows effectively. Anytime you want to evacuate them, you can do as such from Windows Firewall or use the Remove-NetFirewallRule command.

You may also like

Leave a Comment