2

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 1.2.3.4.5 netsh interface ip set dns "Local Area Connection 2" static 1.2.3.4.5 netsh interface ip set dns "WiFi" static 1.2.3.4.5

How can I do, let's say netsh interface ip set dns * static 1.2.3.4.5? (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 1.1.1.1} First think that came up on Google was technig.com/configure-ip-address-using-powershell – HelpingHand Feb 27 '17 at 21:33
1

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 ('1.2.3.4', '5.6.7.8') }"

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:

commands:
  useInternalDns:
    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.