3

I have a DNS server that is misbehaving.

Some of my windows machines only have 2 dns servers

server01  192.0.2.1
server02  192.0.2.2

Some of my windows machines have 3 dns servers

server01 192.0.2.1
server02 192.0.2.2
server03 192.0.2.3

How can I remove server03 (192.0.2.3) from my dns settings using powershell?

PS C:\Windows\system32> Get-DnsClientServerAddress

InterfaceAlias               Interface Address ServerAddresses
                             Index     Family
--------------               --------- ------- ---------------
Ethernet 2                          12 IPv4    {192.0.2.1, 192.0.2.2, 192.0.2.3}
Ethernet 2                          12 IPv6    {}
Loopback Pseudo-Interface 1          1 IPv4    {}

I have very little windows experience. On linux, I would edit the resolv.conf

Update These are windows 2012 R2 servers

2
  • Actually, also on linux chances are that your /etc/resolv.conf has a line # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN May 6, 2015 at 21:26
  • I would say.... find out why some clients have this third address... dont remove it! look at your DHCP, seems like you have a problem with the subnet settings.
    – Cosmic542
    May 7, 2015 at 17:14

1 Answer 1

2

See http://blogs.technet.com/b/heyscriptingguy/archive/2012/02/28/use-powershell-to-configure-static-ip-and-dns-settings.aspx

$wmi = Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'true'"
$DnsServers = "192.0.2.1", "192.0.2.2"
$wmi.SetDNSServerSearchOrder($DnsServers)
2
  • If all of the machines are Windows 8 or 2012, you could use Set-DnsClientServerAddress, but I'm assuming you have some older OSes in the mix. May 6, 2015 at 20:56
  • Also, this doesn't work for some reason if you use SetDNSServerSearchOrder("192.0.2.1", "192.0.2.2") so you have to assign the data to a variable. May 6, 2015 at 21:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .