通过脚本更改Windows服务器上所有NIC的DNS设置

时间:2016-05-25 10:51:37

标签: windows batch-file dns server windows-server-2008

我想更改2008到2012r2之间Windows服务器上所有适配器的DNS设置。

我编写了以下脚本,但是如何在不需要输入适配器名称的情况下更好地完成AKA?

@echo off
netsh interface ipv4 set dns "Local Area Connection" static 10.20.2.72
netsh interface ipv4 add dns "Local Area Connection" 10.20.2.73 index=2
netsh interface ipv4 set dns "Ethernet" static 10.20.2.72
netsh interface ipv4 add dns "Ethernet" 10.20.2.73 index=2
ipconfig /flushdns
ipconfig /all
set choice=
set /p choice="any interfaces still showing old DNS servers? y/n: "
if not '%choice%'=='' set choice=%choice:~0,1%
if '%choice%'=='n' exit
set /p extraint="Enter the interface name here: "
netsh interface ipv4 set dns "%extraint%" static 10.20.2.72
netsh interface ipv4 add dns "%extraint%" 10.20.2.73 index=2
ipconfig /all
ipconfig /flushdns
PAUSE

0 个答案:

没有答案