How can I set my DNS settings using the command-prompt or PS?

13

7

Through the CLI (either cmd.exe or PowerShell) on Windows 7, how do I edit the TCP/IP DNS parameters for a specific network adapter?

Robert Massa

Posted 2010-10-27T19:39:07.923

Reputation: 1 476

Answers

27

netsh.exe

netsh interface ip set dns name="Local Area Connection" source=static addr=none

netsh interface ip add dns name="Local Area Connection" addr=8.8.4.4 index=1
netsh interface ip add dns name="Local Area Connection" addr=8.8.8.8 index=2

netsh interface ip set dns name="Local Area Connection" source=dhcp

ephemient

Posted 2010-10-27T19:39:07.923

Reputation: 20 750

Might need to flush the dns too. ipconfig /flushdns – Frank Fu – 2015-10-28T04:15:15.310

3

Main thing: you can set first DNS as static entry. Next you can only add/append other DNS servers. So, to set primary DNS server use something like this:

netsh interface ip set dns name="Local Area Connection" static 8.8.8.8

for adding/appending other DNS servers you have to use add option, something like this:

netsh interface ip add dns name="Local Area Connection" addr=8.8.4.4 index=2

Pol Hallen

Posted 2010-10-27T19:39:07.923

Reputation: 217

Or to simplify the 2 statement: netsh interface ip add dns "Local Area Connection" 8.8.4.4 2 – yW0K5o – 2019-12-25T17:06:44.917

1

There is a ton of information on managing DNS servers with Powershell, here is a great article from the scripting guys:

If your wanting to manage your own Local DNS settings on your workstation, you can use powershell to connect to WMI, and use the DNS WMI classes.

Brian

Posted 2010-10-27T19:39:07.923

Reputation: 2 934