OPERATING SYSTEMSOS Windows

How to change DNS server using Command Prompt and PowerShell


If you want to change the DNS server using Command Prompt or Windows PowerShell, then this tutorial will be handy for you. Instead of opening the Network Connections window, you can go through this step by step guide and make the change using Command Prompt or PowerShell.

Changing the DNS server addresses is relatively easy – however, if the Control Panel is not opening on your computer due to some reason, you may face a problem. That is when you can use this guide to get the job done. You should note that this tutorial will be helping you to change the Preferred DNS server and Alternate DNS server only.

How to change DNS server using Command Prompt

To change the DNS server using Command Prompt, follow these steps-

  1. Search for cmd in the Taskbar search box.
  2. Click Run as administrator option.
  3. Use the netsh command to show all internet sources.
  4. Note down the Interface Name.
  5. Enter the command to change the server addresses.

At first, you will need to open Command Prompt with administrator privilege. For that, you can search for cmd in the Taskbar search box, and click the Run as administrator option. After opening it, you require to obtain the Interface Name or the internet source name. To get that, enter the following command-

netsh interface show interface

It shows all the previously connected internet source names on your screen. Note down the name of the interface to which you are connected to at this moment.

How to change DNS server using Command Prompt

Following that, exectute these commands-

For IPv4 DNS users:

netsh interface ipv4 set dnsservers "Interface Name" static preferred-DNS-address primary
netsh interface ipv4 add dnsservers "Interface Name" alternate-DNS-address index=2

How to change DNS server using Command Prompt

For IPv6 DNS users:

netsh interface ipv6 set dnsservers "Interface Name" static preferred-DNS-address primary
netsh interface ipv6 add dnsservers "Interface Name" alternate-DNS-address index=2

Don’t forget to replace preferred-DNS-address and alternate-DNS-address with desired DNS server addresses.

How to change DNS server using PowerShell

To change the DNS server using PowerShell, follow these steps-

  1. Search for powershell in the Taskbar search box.
  2. Click the Run as Administrator option.
  3. Enter the Get-DnsClientServerAddress command to show InterfaceAlias.
  4. Enter the command to change DNS server addresses.

At first, you need to open elevated Windows PowerShell window. For that, you can search for powershell and click the Run as Administrator option. Next, enter the following command and note down the InterfaceAlias name.

Get-DnsClientServerAddress

After that, enter the following command to change IPv4 and IPv6 addresses.

Set-DNSClientServerAddress "InterfaceAlias" –ServerAddresses ("preferred-DNS-address", "alternate-DNS-address")

It requires you to change three things before hitting the Enter button:

  • InterfaceAlias,
  • Preferred-DNS-address,
  • Alternate-DNS-address.

change DNS server using Command Prompt and PowerShell

Before pressing the Enter button, it would look like this-

Set-DNSClientServerAddress "Wi-Fi" –ServerAddresses ("1.1.1.1","1.0.0.1")

After making these changes, you might have to flush the DNS cache.

TIP: Read more about some of the best DNS server providers – Comodo Secure DNS, OpenDNS, Google Public DNS, Yandex Secure DNS, Cloudflare DNS, Angel DNS, etc.

How to change DNS server using PowerShell

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *