改IP地址命令的命令及批处理

有时候我们想在动态IP与静态IP之间切换或不想手动改来改去,可以用这个方法
 
固定IP:
@echo off
netsh interface ip set address name="本地连接" source=static addr=192.168.0.6 mask=255.0.0.0
netsh interface ip set address name="本地连接" gateway=192.168.0.1 gwmetric=0
netsh interface ip set dns name="本地连接" source=static addr=202.101.172.35 register=PRIMARY
netsh interface ip add dns name="本地连接" addr=202.101.172.47
自动获取:
@echo off
netsh interface ip set address "本地连接" dhcp
netsh interface ip set dns "本地连接" dhcp
 
命令格式
netsh interface ip set <网络连接属性> <网络连接名称> static <IP地址> <子网掩码> <网关IP> <跃点计数>
netsh interface ip add dns <IP地址>

也可以把下面代码存成.bat文件,直接运行就可以设定静态IP了,这个简单点,没上面复杂
netsh interface ip set address "本地连接" static 192.168.18.100 255.255.255.0 192.168.18.1 1
netsh interface ip set dns "本地连接" static 202.101.172.35
netsh interface ip add dns "本地连接" 202.101.172.47

你可能感兴趣的:(IP,netsh,动态IP与静态ip切换,ip批处理)