命令行修改本地IP地址和DNS服务器地址
netsh interface show interface //查看网卡名字
netsh interface ipv4 set address name="Ethernet0" static 192.168.126.138 255.255.255.0 192.168.126.2 //设置静态IP
netsh interface ip set dns “Ethernet0” static 119.29.29.29 //设置主DNS(设置完静态IP,然后连续执行这条命令出错,原因不明,请参考示例代码用完整版本的)
netsh interface ip add dns “Ethernet0” 8.8.8.8 index=2 //设置备用DNS
netsh interface ip set address name="Ethernet0" source=dhcp //设置自动获取IP地址
netsh interface ip set dns name="Ethernet0" source=dhcp //设置自动DNS
示例代码(可复制到txt保存为bat右键管理员运行):
netsh interface ip set address name="Ethernet0" source=dhcp
netsh interface ip set dns name="Ethernet0" source=dhcp
timeout /T 2 /NOBREAK
netsh interface ipv4 set address name="Ethernet0" static 192.168.126.139 255.255.255.0 192.168.126.2
netsh interface ip set dns name="Ethernet0" source=static addr=119.29.29.29 register=primary
netsh interface ip add dns name="Ethernet0" addr=8.8.8.8 index=2
参考链接:
1、在Win10中手动添加/修改本地IP https://zhuanlan.zhihu.com/p/366445441
2、Windows下使用命令行设置ip地址的DNS服务器 https://www.cnblogs.com/freeweb/p/5061025.html
3、CMD命令更改IP地址三招 https://blog.51cto.com/dawoniu/144342