Change DNS Server for Network Interface Powershell

As a System Administrators, you will be asked or required to use specific DNS for specific computers. This can be very easily done via GUI, but require few steps to perform it. Also you may need to do this on number of computers.

For me, I normally perform actions via powershell if I have to do certain tasks more than twice.

So To change the DNS Server foe a particular Interface, you can use a cmdlet called Set-DnsClientServerAddress. 

The Set-DnsClientServerAddress cmdlet sets one or more IP addresses for DNS servers associated with an interface. This cmdlet statically adds DNS server addresses to the interface. If this cmdlet is used to add DNS servers to the interface, then the DNS servers will override any DHCP configuration for that interface.

But before we do it, we need to know the Interface index or alias to perform this action.

Get-NetAdapter or Get-DNSClient, will give you Interface alias and Index.

you can use either of the following command to do so

Set-DnsClientServerAddress -InterfaceAlias “InterfaceAliasName”
Set-DnsClientServerAddress -InterfaceIndex “InterfaceIndexno”

set-dnsclientserveraddress

Then you will to specify switch “-ServerAddresses”, which is used to specifies a list of DNS server IP addresses to set for the interface.

Lets quickly check ipconfig details or current DNS Settings

ethernet01

As you can see that DNS Server is pointing to 192.168.1.1 twice and needs to be fixed. So I will run the Set-DnsClientServerAddress cmdlet to fix it.

Set-DnsClientServerAddress -InterfaceAlias “Ethernet0” -ServerAddresses “192.168.1.110,192.168.1.1”

This will set the DNS Servers for that particular Interface to “192.168.1.110,192.168.1.1”

ethernet02

After the Set-DnsClientServerAddress is run, DNS Server addresses are fixed.

 

Good thing about Powershell that you can invoke this same command on any number of Computers at once. For e.g. you can run this command on 100 servers in couple of seconds only and fixed the lot.

 

Lastly, please do give feedback. Enjoy Reading.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s