设置静态IP
@echo OFF //不显示后续命令行及当前命令行
set netname="要修改的网络的名字"
set ip=XXX.XXX.XXX.XXX
set subnetmask=XXX.XXX.XXX.XXX
set gateway=XXX.XXX.XXX.XXX
set dns1=XXX.XXX.XXX.XXX
set dns2=XXX.XXX.XXX.XXX
@netsh interface ip set address name=%netname% source=static addr=%ip% mask=%subnetmask% gateway=%gateway% gwmetric=1 //默认网关的跃点数
@netsh interface ip set dns name=%netname% source=static addr=%dns1% primary //主要的
@netsh interface ip add dns name=%netname% addr=%dns2% index=2 //为指定的DNS服务器地址
设置自动获取IP及DNS
@echo OFF
set netname="以太网"
@netsh interface ip set address name=%netname% source=dhcp
@netsh interface ip set dns name=%netname% source=dhcp
用管理员身份运行即可