Command to Change Windows 10 DNS with CMD or PowerShell

Windows is an operating system intended to be used in graphics mode. Except for some advanced and administrative tasks, everything else can be done perfectly with the mouse through its programs, tools and settings. However, that it can be done with the mouse does not mean that it is the easiest or fastest way to do it. And it is that Windows consoles, such as CMD and PowerShell, hide tricks that allow us to carry out certain configurations much faster than from the system options. For example, the change of DNS .

The DNS servers are in charge of translating the domain names of the websites that we visit by their corresponding IPs so that we can visit the pages. Without them, by typing “www.google.es” in the browser we would not be able to visit the page as we do not know which address it corresponds to. A good DNS not only ensures that we can resolve and visit any page, but it can also help us navigate faster.

Command to Change Windows 10 DNS

DNS can be changed from the same section from which we can change the IP in Windows 10. However, if we usually change often, for whatever reason, you may have to look for the option in the Windows configuration menu no be it quicker or easier.

Therefore, below, we leave you an essential CMD trick that will allow us to change Windows DNS with a simple command. Of course, this can be very useful for us to create a script, in PowerShell or CMD, that allows us to change the DNS implement by double clicking.

Change DNS from CMD

The first thing we must do in order to carry out this task is to know the name of the network to which we are going to make this change. We can find this out very easily by executing the following command, within any CMD window , yes, with Administrator permissions:

netsh interface show interface

Averiguar nombre red CMD netsh

In our case, the main connection is Ethernet, but the name may vary if, for example, we use Wi-Fi or have it customized. We write down this interface name, and continue with the process.

The next step will be to execute the command that will allow us to make this change. Within the same CMD window, what we have to do is execute the following:

To change the primary DNS:

netsh interface ipv4 set dnsservers "Nombre_red" static IP_DNS primary

To add a secondary DNS:

netsh interface ipv4 add dnsservers "Nombre_red" IP_DNS index=2

Of course, we must change network_name to the name that we have known in the previous point, and IP_DNS to the IP of the primary DNS that we want to use. For example, in our case the first example would be, for Google DNS:

netsh interface ipv4 set dnsservers "Ethernet" static 8.8.8.8 primary

Once done, we clean the DNS cache with “ipconfig / flushdns” and that’s it.

Change DNS from PowerShell

If what we want is to be able to use the PowerShell terminal , this can also be done from it. The only thing we need is to open the console with Administrator permissions, and the first thing is to identify the name of the network (which, again, in our case is Ethernet, but it can vary):

Get-DnsClientServerAddress

PowerShell nombres interfaces

Now, to change the DNS using the PowerShell tool, what we must do is run the following command in the console. Of course, we must change “Ethernet” for the name of our network, and the IPs for the primary and secondary server that we want to assign:

Set-DNSClientServerAddress "Ethernet" –ServerAddresses ("8.8.8.8","8.8.4.4")

Finally, we clean the DNS cache with the command we saw in the previous point and voila, we will be using the new DNS.