How to Use the Netsh Command to View and Configure IPv4 Networks

Windows is an operating system in which most of the actions can be carried out using its graphical interface. However, sometimes we have to resort to using a series of commands in a command prompt or Windows PowerShell window. In this case, we are going to talk about one that would allow us to change the configuration of our network interfaces, both for IPv4 and for IPv6. In this tutorial we will explain how to use the Windows netsh command to view and change the configuration of an IPv4 network.

The first thing we are going to do is get to know the netsh command and how we can use it. Then we will explain some of its basic parameters of use together with some examples of use with their corresponding syntax so that you can see and change the configuration of an IPv4 network.

Use the Netsh Command to View and Configure IPv4 Networks

What is the netsh command and how to use it

The netsh command could be defined as a command line utility that will allow us to display or modify the network configuration of a running computer. Its main functions are related to the visualization, modification, administration and diagnosis of a network configuration. This tool is available in Microsoft Windows operating systems in different versions like 2000, XP, 7, 8, 10, Server 2012 and more.

Regarding its form of execution, we can do it in two different ways:

  1. Windows PowerShell.
  2. Symbol of the system.

Next, we are going to put an example with each one, although throughout the tutorial we will do the examples using a command prompt window.

We are going to start with PowerShell for which we are going to follow these steps:

  1. Let’s go to the Windows start menu .
  2. We write Windows PowerShell and press enter.

So we write the netsh command like this:

Its way of working is different from what we use in a command prompt window. After the symbol « we would put the parameters, in this case it would be the one of the « ? »To view command options. As you can see, it offers these results:

On the other hand, then we would have the option of working with the netsh command in a command prompt window for which we would follow these steps.

  1. We go to the Windows start menu .
  2. We type CMD and press enter.

Here the way of working is different, the entire command is written in one go and executed by pressing enter. Options are separated by entering the / (slash) or (single hyphen) operators. For example, like the previous case to see the options of the netsh command it would be the « ? »And to enter it correctly it would be« /? «. Thus, the command that we should introduce is:

netsh /?

This is the answer we would get:

As can be seen, most of the options would be included in both, although it should be noted that the way of working would be different. In this tutorial we are going to work in the latter way, that is, with a command prompt window.

Netsh Syntax and Parameters

Every time a command is entered, a guideline must be followed, which is simply to follow the order established by its syntax. Then we have to put the parameters with their corresponding symbol, which is usually a slash « / « or a hyphen «-«.

This would be the syntax of the command:

netsh [ -a ArchivoDeAlias ] [ -c Contexto ] [ -r EquipoRemoto ] [ -u [ NombreDeDominio ] NombreDeUsuario ] [ -p Contraseña | *] [{ ComandoNetsh | -f ArchivoDeScript}

We could use the netsh command with these parameters:

  • -a returns to the netsh prompt after AliasFile execution.
  • AliasFile that specifies the name of the text file that contains one or more netsh commands.
  • -c you specify the context you want to use, for example, WLAN.
  • -r you are indicating that you want the command to be executed on a remote computer.
  • -u states that you want to use the netsh command on a specific user account.
  • -p to specify that we want to provide a password to the user account.
  • -f after executing a script exits netsh.

One way that can help us to know how we can combine the operators that we can use is by knowing the context of the principal. Therefore, if we wanted to know the commands available for wlan we would use:

netsh -c wlan

And then putting the ? We could see the commands that we can use:

Save and restore network settings with the netsh command

Thanks to netsh we can also export the network configuration to a text file. Thus, in case of network problems we could restore to the values we had before, thanks to that backup. The first thing we have to do before exporting that network configuration is to create a network folder to store our backup file. In this case we are going to create a folder called «networks» in our drive C:. So, to save our configuration in a file called configuration.txt we will execute the netsh command like this:

netsh dump >> c:redesconfiguracion.txt

Then if we double click on the file we can see its content:

In the event that we need to restore our network configuration we would use this:

netsh -fc:redesconfiguracion.txt

Other netsh commands we can use

An important command is the one that shows us the names of the interfaces that we have on our computer, from here we will point the name of the interface that we are going to configure:

netsh interface show interface

For example, we could choose our IPv4 interface and establish a static IP for our computer like this:

netsh interface ipv4 set address "Wi-Fi" static 192.168.1.40 255.255.255.0 192.168.1.1 1

Now we go to the netsh command in relation to wireless connections . For example, if I want to find out the Wi-Fi network profiles that I have saved on my computer

netsh wlan show profiles

And then we would see that we have these Wi-Fi networks saved:

If we want to prevent a Wi-Fi network from connecting automatically we would have to use:

netsh wlan set profileparameter name=Nombre de red connectionmode=manual

In network name we would replace it with the name of our Wi-Fi network. On the other hand, if we want our Wi-Fi to connect automatically:

netsh wlan set profileparameter name=Nombre de red connectionmode=auto

Also using the netsh command we can see the configuration of the Wi-Fi interface:

netsh interface ipv4 show address Wi-Fi netsh interface ipv4 show dns Wi-Fi

Instead of the Wi-Fi interface, we could also do the same with the equipment connected by network cable

netsh interface ipv4 show address ethernet netsh interface ipv4 show dns ethernet

Here’s an example:

Regarding the firewall, we could also use a series of commands. In the case of wanting to open port 80, we would execute the following:

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

If we want to remove the rule from a port we would use this:

netsh advfirewall firewall delete rule name= rule name protocol=udp localport=500

We could also restore the firewall defaults like this:

netsh advfirewall reset

Now it’s the turn to work with the DNS servers . So we could establish the first DNS server:

netsh interface ipv4 set dnsservers "Wi-Fi" static 8.8.8.8 validate=no

We would put the secondary server this way:

netsh interface ipv4 add dnsserver "Wi-Fi" 8.8.4.4 index=2 validate=no

The index parameter is going to assign an order number to the server. In the first DNS server after the IP we could have put index = 1 but it is not necessary.

We can also establish that the network configuration of the Wi-Fi interface was dynamic through DHCP. For which we would have to execute the nestsh command twice like this:

netsh interface ipv4 set address "Wi-Fi" dhcp netsh interface ipv4 set dnsservers "Wi-Fi" dhcp

As you can see, using the netsh command we can see and modify many aspects of our network connection.