Windows下自动切换IP脚本

在不同环境使用电脑经常要切换IP,利用netsh interface ip命令可以轻松切换IP和DNS:

     netsh interface ip有以下命令:

     add            - 在一个表格中添加一个配置项。
     delete         - 从一个表格中删除一个配置项。
     dump           - 显示一个配置脚本。
     help           - 显示命令列表。
     install        - 安装 IP 协议。
     reset          - 重置 IP 配置。
     set            - 设置配置信息。
     show           - 显示信息。
     uninstall      - 卸载 IP 协议。

 

     netsh interface IP set有以下的命令:
     set address    - 设定通向接口的 IP 地址或默认网关。
     set compartment - 修改分段配置参数。
     set dnsservers - 设置 DNS 服务器模式和地址。
     set dynamicportrange - 修更改态端口分配所使用端口的范围。
     set global     - 修改全局配置常规参数。
     set interface  - 修改 IP 的接口配置参数。
     set neighbors  - 设置邻居地址。
     set route      - 修改路由参数。
     set subinterface - 修改子接口配置参数。
     set winsservers - 设置 WINS 服务器模式和地址。

 

     简单示例1:设置固定IP,保存为bat文件

   @echo off
   @rem 设置IP为192.168.0.1,子网掩码为255.255.255.0,默认网关为192.168.0.254
   netsh interface ip set address local static 192.168.0.1 255.255.255.0 192.168.0.254
   @rem 设置首选的DNS服务器192.168.0.254
   netsh interface ip set dns local 192.168.0.254
   @rem 添加DNS服务器202.106.196.115
   netsh interface ip add dns local 202.106.196.115 index=2

 

    示例2:自动获取

   @echo off
   netsh interface ip set address name="local" source=dhcp
   netsh interface ip set dns name="local" source=dhcp
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值