快速更改IP地址及DNS地址 netsh interface ip set 命令

来自: http://hi.baidu.com/coolggg/blog/item/0958a3106ded4f0c213f2ef7.html

由于工作环境的变换或内外网切换时,使ip地址不得不频繁的更换 ,为了避免更改ip地址带来的麻烦,用dos命令做一个批处理文件来实现ip地址和dns地址的快速更改。一、命令介绍

这里用到的DOS命令是:netsh interface ip set (address/dns) 或简写为 netsh   int ip set (address /dns)
用法格式:
netsh interface ip set address[name=]<string>
[[source=]dhcp |
[source=] static [addr=]IP address [mask=]IP subnet mask]
[[gateway=]<IP address>|none [gwmetric=]integer]

netsh interface ip   set dns [name=]<string> [source=]dhcp|static [addr=]<IP address>|none
[
参数说明:
name        - 接口名称。
source      - 下列值之一:
dhcp: 对于指定接口,设置用 DHCP 配置 IP地址或DNS服务器。
static: 设置使用本地静态配置设置 IP地址或DNS服务器。
gateway     - 下列值之一:
<IP address>: 您设置的 IP 地址的指定默认网关。
none: 不设置默认网关。
gwmetric    - 默认网关的跃点数。如果网关设置为 ‘none’,则不应设置此字段。
只有在 ’source’ 为 ’static’ 时才设置下列选项:
addr         - 指定接口的 IP 地址。
mask        - 指定 IP 地址的子网掩码。
register     - 下面的值之一:
none: 禁用动态 DNS 注册。
primary: 只在主 DNS 后缀下注册。
both: 在主 DNS 后缀下注册,也在特定连接后缀下注册。
二、制作批处理文件(以内外网为例)
设“本地连接”上外网时ip地址为自动获取,DNS为202.99.224.8;上内网是ip地址为192.168.1.123 掩码255.255.255.0 网关192.168.1.1,DNS为自动获取。
上外网的代码是
@echo off
set dns=202.99.224.8

netsh interface ip set address name=”本地连接” source=dhcp
netsh interface ip set dns name=”本地连接” source=static addr=%dns%

把这段代码复制到一个文本里面,将文本另存为外网ip.bat”(文件名可随意,扩展名必须为bat)。
上内网的代码
@echo off
set name=”本地连接”
set ipaddress=192.168.1.123
set mask=255.255.255.0
set gateway=192.168.1.1

netsh interface ip set address name=%name% source=static addr=%ipaddress% mask=%mask% gateway=%gateway% 1
netsh interface ip set dns name=”本地连接” source=dhcp

把这段代码复制到一个文本里面,将文本另存为内网ip.bat
上内网的时候换上内网网线,执行“内网ip.bat”,上外网的时候换上外网的网线,执行“外网ip.bat”。
大家在使用时根据自己的情况根改IP地址,掩码,网关和DNS。

批处理修改IP
 
 
@ echo off
rem 设置变量
set Nic=本地连接
rem //可以根据你的需要更改,
set Addr=10.207.11.140
set Mask=255.255.255.192
set Gway=10.207.11.129
set Dns1=10.207.1.20
set Dns2=10.207.1.21
rem //以上依次为IP地址、子网掩码、网关、首选DNS、备用DNS
echo ------------------------------------------------------
echo 正在进行IP设置,请稍等
rem //可以根据你的需要更改
echo. IP地址 = %Addr%
echo. 子网掩码 = %Mask%
netsh interface ip set address name=%Nic% source=static addr=%Addr% mask=%Mask% >nul
echo. 网关 = %Gway%
netsh interface ip set address name=%Nic% gateway=%Gway% gwmetric=1 >nul
echo. 首选DNS = %Dns1%
netsh interface ip set dns name=%Nic% source=static addr=%Dns1% register=PRIMARY >nul
echo. 备用DNS = %Dns2%
netsh interface ip add dns name=%Nic% addr=%Dns2% index=2 >nul
echo ------------------------------------------------------
echo IP设置完成!
netsh interface ip add dns name=%Nic% addr=%Dns3% index=2 >nul
rem pause >nul

  • 6
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
### 回答1: netsh interface ip set address是一个Windows命令行工具,用于设置网络接口的IP地址。它可以通过命令行界面或批处理脚本来使用,以便在Windows操作系统中自动化网络配置。该命令可以设置IP地址、子网掩码、默认网关和DNS服务器等网络参数。 ### 回答2: Netsh是Windows操作系统的一个命令行工具,其可以用于管理网络配置和网络接口。其中,netsh interface ip set address命令是用来设置网络接口的IP地址和子网掩码的命令。 具体来说,可以通过以下几个参数来使用该命令: 1. Interface:指定需要进行配置的网络接口的名称或索引号。 2. Address:指定需要配置的IP地址,可以是IPv4或IPv6地址。 3. Mask:指定需要配置的子网掩码,同样可以是IPv4或IPv6格式。 4. Gateway:指定网关的IP地址。 例如,如果我们需要将网络接口“Local Area Connection”上的IP地址设置为192.168.1.100,子网掩码为255.255.255.0,网关为192.168.1.1,则可以使用以下命令netsh interface ip set address name="Local Area Connection" static 192.168.1.100 255.255.255.0 192.168.1.1 其中,name参数指定了网络接口的名称,static参数表示需要使用静态IP地址。注意,如果需要使用DHCP获取IP地址,则需要将static参数改为dhcp。 总之,netsh interface ip set address命令可以帮助我们在命令行方式下进行网络接口的配置,从而更加方便和快速的管理网络设置。 ### 回答3: netsh interface ip set address 是 Windows 操作系统提供的一条命令行指令,用于设置网络接口的 IP 地址、子网掩码、默认网关等网络参数。这条指令可以通过管理员权限的 cmd 或 PowerShell 窗口执行。 语法格式如下: netsh interface ip set address "接口名称" static IP地址 子网掩码 [网关] [跳数] 其中,“接口名称”参数指定了需要设置网络参数的网卡接口,可以通过执行 netsh interface ip show interface 命令查看可用的接口名称。static 表示使用静态 IP 地址,也可以使用 dhcp 表示自动获取 IP 地址IP地址、子网掩码、网关和跳数都是用十进制点分格式表示的。网关和跳数是可选参数,如果不设置,则默认使用本地网络的默认网关和 TTL 值。 下面是一个示例,设置名称为“以太网”的网卡接口的 IP 地址为 192.168.1.100,子网掩码为 255.255.255.0,网关为 192.168.1.1,跳数为 32。 netsh interface ip set address "以太网" static 192.168.1.100 255.255.255.0 192.168.1.1 32 使用 netsh interface ip set address 命令可以方便地修改网络接口的网络配置,适用于需要手动配置局域网 IP 地址的场景。但是,此命令需要管理员权限才能执行,如果操作不当会导致网络连接问题,因此需要谨慎操作。在修改网络配置之前,建议备份当前的网络配置,以便需要时能够快速恢复。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值