如何用脚本设置IP(一设置某一特定ip)
首先新建一个txt文档,输入以下命令,另存为setip1.bat
@echo offecho 设置ip地址为某一个特定ip(192.168.1.100)netsh interface ip set address name=本地连接 static 192.168.1.100 255.255.255.0 192.168.1.1netsh interface ip set dnsservers 本地连接 static 8.8.8.8 primarynetsh interface ip add dnsservers 本地连接 114.114.114.114 index=2echo 设置成功
代码说明
一、netsh 是一个windows系统本身提供的功能强大的网络配置命令行工具
二、netsh interface ip set address name=本地连接 static 192.168.1.100 255.255.255.0 192.168.1.1
- netsh interface ip set address 意思是设置ip地址
- name=本地连接 是指修改哪一个网卡的ip地址,在win7中是本地连接,在win10中是以太网,在有些情况下网卡名称后面可能会加上后缀,想要确保设置成功,可以如截图中一样复制多次,更改网卡名称为(本地连接 1, 本地连接 2,本地连接 3……)
- static 设置静态ip的意思
- static 后面分别跟 ip地址 子网掩码 默认网关,中间空格隔开
三、netsh interface ip set dnsservers 本地连接 static 8.8.8.8 primary
设置首选DNS服务器,注意dnsservers和primary
四、netsh interface ip add dnsservers 本地连接 114.114.114.114 index=2
设置备用DNS服务器,注意dnsservers和index=2
如何设置为自动获取IP地址,请见下一篇文章