删除所有接口上的静态 IP 和 DNS - 批处理

Remove Static IP & DNS on all Interfaces - Batch

我需要一个 Window 的批处理脚本,它将删除静态 IP 地址(更改为 DHCP),删除设置的 DNS,并启用所有网络接口 而无需指定接口名称;因为某些接口的名称可能不同。

我昨晚创建了这个,一切似乎都按预期的方式工作。

@echo off

: Disable Static IP/Enable DHCP    Remove DNS     Enable NICs
for /f "skip=2 tokens=3*" %%i in ('netsh interface show interface') do (
netsh int ip set address "%%j" dhcp >nul 2>&1
netsh int ip set dns "%%j" dhcp >nul 2>&1
netsh interface set interface name="%%j" admin=enabled >nul 2>&1
)

如果您想更进一步并清除 DNS 缓存,请将此添加到下一行。

ipconfig /flushdns >nul 2>&1

您可以使用此脚本创建批处理文件,将您的 IP 从静态 IP 更改为 DHCP。

@echo off
netsh interface ipv4 set address name="Wi-Fi" source=dhcp   
@echo off 
netsh interface ipv4 set dns name="Wi-Fi" source=dhcp