How to Disable Windows Firewall With Command Line.
The Windows firewall is tricky. It limits your downloads at times, prevents you from connecting to your PC remotely and blocks applications from launching, which is very annoying. But for now, this is the top-notch security feature provided by Windows if you know how to use it. You can configure your firewall to block certain applications from accessing the Internet and protect your local data.
It is very easy to prevent applications from accessing the Internet using a graphical interface. just go to the start menu and search for “Firewall and Network Protection”. In the dialog box, click Domain Network and turn off the firewall. Likewise, you must turn off the firewall for the private and public network. If you need to turn off Internet-only firewall, turn off Public network-only firewall.
Disable Windows Firewall using command line
However, if you, like me, prefer to turn off Windows Firewall using the command line, here’s a quick way to do it on Windows 10 and 7.
Open a command prompt. Go to the Start menu, type Command Prompt. Right click it and select “Run as administrator”. This command requires elevated permissions to disable the firewall, so it must be run as administrator.
At the command prompt, type netsh advfirewall, disable the status of all profiles.
This will disable the firewall for all 3 networks. To turn it back on, replace “off” with “on”. netsh advfirewall sets the status of all profiles to
Like the terminal in macOS and Linux, Windows cmd also allows you to navigate through the last used commands using the up and down arrows on your keyboard. So, if you want to execute the previous last command, just press the up arrow once, edit the command (turn it off) and press Enter.
Block any application in firewall (command line)
To block any application in the firewall, we first need to understand what an inbound and outbound rule is. Inbound traffic rules define either block or allow an application to receive data on your computer. Outbound rules are defined to block or allow an application to send data from your computer.
Blocking something in the firewall using the GUI is very easy. All you have to do is go to firewall and network protection.
Click Advanced Options and go to the Outbound Rules tab. Click New Rule on the right side of the window. In the pop-up window, select the Rule Type as Program. Click Next, and further steps, such as specifying the path to the program, are self-explanatory.
However, doing the same with the command line is not as intuitive. First, you need to decide if you need to block the application from receiving or sending data from the Internet. Let’s say you want to prevent the Chrome app from accessing the Internet.
Next, we need to find the location of the EXE file on our system. It should usually be in C: Program Files unless you have manually defined it.
Go to the .exe file and copy the path. In my case for google chrome the path will be: C: Program Files (x86) Google Chrome Application chrome.exe
After locating the file, all you need to do is open a command prompt as administrator and enter the following command: netsh advfirewall firewall add rule name = “Chrome block” program = “C: Program Files (x86) Google Chrome Application chrome.exe “dir = out action = block profile = public
Now, when I open Chrome, Internet access is disabled.
Block any application in the firewall with its port number
If you want to block the application by port number. First, you need to determine the port number. To do this, go to the Start menu and type Resource Monitor. Right click it and select “Run as administrator”.
When the dialog box opens, go to the Networking tab and expand the Listening Ports section by clicking on it.
Once you get the port number, use the following command to block that specific port. netsh advfirewall firewall add rule name = “Chrome block” localport = 443 protocol = tcp dir = out action = block profile = public
If you are not sure of the exact port number, you can also block the port range by specifying port = 1000-2000.
To remove this outbound rule, enter the following give command with the rule name you specified earlier.
This should fix the situation, and Chrome should be able to access the Internet.
Packaging
These methods allow you to block any particular application from accessing the Internet. This can be used against suspicious applications to protect your data from being sent to private networks or the Internet. If you have any problems with the step, you can comment on the error and I can help you with the solution.
Read: How to reset TCP / IP on Windows, Linux and macOS