How to Control the Windows Firewall from the Netsh Command Line

Having security tools is essential to avoid problems that could compromise our systems. There are many viruses and threats that are present on the network, as well as multiple attack methods used by cybercriminals. Luckily we can make use of many programs that help us protect ourselves. One option is to have a good firewall. In this article we are going to talk about how to control the Windows firewall from the Netsh command line .

How to control the Windows firewall from Netsh

Windows is undoubtedly the most widely used operating system on desktop computers. This has its positive and negative points. Regarding the first, we can say that there are a large number of programs and options for almost everything. This gives us a very wide range of possibilities. On the other hand, regarding the negative we can say that the fact of being so widely used will also help hackers to have more options where to attack.

Control the Windows Firewall from the Netsh

A very useful tool that is incorporated with Windows is its firewall. This will allow us to control the use of certain applications connected to the network, for example. There are different configurations that we can take into account at all times.

This time we are going to explain how to control the Windows firewall from Netsh , also known as Network Shell.

To access we must enter the Command Prompt. Let’s go to Start, write CMD and run it in administrator mode. Later we execute netsh advfirewall . A list like the one we see in the image below will appear.

Usar el firewall de Windows con comandos

We will see a series of options that we can use to configure within the Windows firewall from Netsh. For example, to simply turn the firewall on or off you have to execute the command:

netsh advfirewall set currentprofile state on

For example, let’s say we want to enable port 80 of the firewall and we want to do it from the command line. In this case we would have to execute:

netsh advfirewall firewall add rule name = “Open Port 80” dir = in action = allow protocol = TCP localport = 80

If we want to delete a program or a port we can also do it easily. In this case we would have to execute:

netsh advfirewall firewall delete rule name = rule name program = »C: ProgramaPrograma.exe» (in the case of a program)

netsh advfirewall firewall delete rule name = rule name protocol = udp localport = 500 (in the case of a port, whatever)

If we have made changes to test some parameters and want to go back to how it was originally, we can easily do that. You simply have to restore the default values, which we can also do from the command line. This time you have to run:

netsh advfirewall reset

In short, as we can see, we can use different options to configure the Windows firewall easily from the command line. An alternative to using it visually, with the application integrated into Microsoft‘s own operating system.

Why should we use a firewall

As we have indicated, it is very important to always have security programs and tools that protect us. There are many threats on the Internet, although there are also many defensive options, beyond even a simple antivirus. This is something that we must apply regardless of the type of operating system or device we use.

A firewall or firewall is a system that helps us block unwanted and unauthorized access to a computer or a network. This allows us to avoid intruders that can sneak malware and other attacks that compromise the security of the devices and our own privacy.

For example with a firewall we will be able to block or allow access to the network to certain applications that we have installed. In this way we will achieve greater security, as well as reduce the field of action that possible intruders would have to carry out their attacks.

The firewall can block access to applications, ports, connections … We can configure it very broadly, with different options and characteristics depending on the type. In the case of the Windows firewall, it offers a series of options that we can modify even from the command line, as we have seen.