How can I use netsh or a similar command to add my DNS servers to all my interfaces, and not naming them one by one.

Normally I would do: netsh interface ip set dns "Local Area Connection" static netsh interface ip set dns "Local Area Connection 2" static netsh interface ip set dns "WiFi" static

How can I do, let's say netsh interface ip set dns * static (of course, this one does not work) so I don't have to enter the names of all my interfaces?

Thank you!

  • 1
    I'd suggest taking a look at Powershell. To get you going: foreach ($c in Get-NetAdapter){write-host Set-DnsClientServerAddress -InterfaceIndex $c.interfaceindex -ServerAddresses} First think that came up on Google was technig.com/configure-ip-address-using-powershell – HelpingHand Feb 27 '17 at 21:33

Thanks to @HelpingHand, this worked for me:

powershell "foreach ($c in Get-NetAdapter) { write-host 'Setting DNS for' $c.interfaceName ; Set-DnsClientServerAddress -InterfaceIndex $c.interfaceindex -ServerAddresses ('', '') }"

In my case I was running it from Elastic Beanstalk's ebextensions file, so that my Windows EC2 instances would boot up using private DNS servers:

    command: powershell "foreach...
    ignoreErrors: false
    waitAfterCompletion: 0

This way the custom DNS servers are always added, even when the interface name and index change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.