windows 网卡配置的设置命令
(1)设置为DHCP自动分配
netsh interface ip set address "本地连接" dhcp
netsh interface ip set dns "本地连接" dhcp
(2) 设置为静态IP信息
netsh interface ip set address "本地连接" static 10.10.2.1 255.255.255.0 10.10.2.254
netsh interface ip set dns "本地连接" static 114.114.114.114
netsh interface ip add dns "本地连接" 8.8.8.8
(3)查看当前的IP配置信息
netsh interface ip show address/config/dns
(4)查看windows的网络配置文件
netsh -c interface dump
(5)批处理的形式
echo #设静态IP
netsh interface ip set address name="本地连接" source=static addr=192.168.1.1 mask=255.255.255.0
echo #设默认网关
netsh interface ip set address name="本地连接" gateway=192.168.1.254 gwmetric=0
echo #设首选dns
netsh interface ip set dns name="本地连接" source=static addr=192.168.1.10 register=PRIMARY
echo #设备用dns
netsh interface ip add dns name="本地连接" addr=192.168.1.20 index=2
netsh interface ip set wins name="本地连接" source=static addr=none
echo #
echo #显示“本地连接”配置结果
netsh interface ip show config 本地连接
echo #
echo # "本地连接" 的接口 IP 配置
echo #设自动获取ip
netsh interface ip set address name="本地连接" source=dhcp
echo #设自动获取dns
netsh interface ip set dns name="本地连接" source=dhcp register=PRIMARY
echo netsh interface ip set wins name="本地连接" source=dhcp
echo #显示“本地连接”配置结果
netsh interface ip show config 本地连接
echo # 接口 IP 配置结束
(6)导出配置文件修改再执行导入
netsh interface dump>网络配置.netsh
修改“网络配置.netsh”文件,保留、修改其中需要的pushd及popd段,及段中需要的行。
以后再在需要时修改配置:
netsh exec 网络配置.netsh
或
netsh 网络配置.netsh
①追加
DHCP : netsh interface ip set address name=Adapter source=DHCP
ip : netsh interface ip add address name=Adapter addr=ip mask=maskip gateway=gatewayip
DNS : netsh interface ip add DNS name=Adapter addr=DNSip
WINS : netsh interface ip add WINS name=Adapter addr=WINSip
②修正
DHCP : netsh interface ip set address name=Adapter source=DHCP
ip : netsh interface ip set address name=Adapter source=STATIC addr=ip mask=maskip gateway=gatewayip
DNS : netsh interface ip set DNS name=Adapter source=STATIC addr=DNSip
WINS : netsh interface ip set WINS name=Adapter source=STATIC addr=WINSip
③删除
ip : netsh interface ip delete address name=Adapter addr=ip
DNS : netsh interface ip delete DNS name=Adapter addr=DNSip
WINS: netsh interface ip delete WINS name=Adapter addr=WINSip