用户登录
用户注册

分享至

CMD命令行下修改网络IP设置的方法

  • 作者: 隔壁全叫我老王
  • 来源: 51数据库
  • 2021-09-21

比较简单的版本,你只要知道需要设置的ip与dns信息就可以了

@echo.
@echo      -----------------------------------------
@echo      本命令将自动为“本地连接”填写以下内容:
@echo        ip地址:192.168.0.118
@echo        网关: 192.168.0.1
@echo        dns:  202.96.128.86
@echo      -----------------------------------------
@echo. 
@echo.
@echo 没有接入局域网的用户,开机时,系统因搜索不到ip地址,进系统的速度稍慢,请在
@echo 本地连接填上ip地址(任意),就可加快系统的启动速度。所以本批处理仅是为单机拨
@echo 号上网的用户准备的,局域网用户请不要理会本批处理,乱改可能导致您上不了网。
@echo.
@echo.
@ pause
@echo off
netsh interface ip set address name="本地连接" source=static addr=192.168.0.118 mask=255.255.255.0 gateway=192.168.0.1 1
netsh interface ip set dns name="本地连接" source=static addr=202.96.128.86

不累述,直接两个例子:

c:\>ipconfig (首先用ipconfig这个命令看一下更改之前的ip地址) 
 
windows 2000 ip configuration 
ethernet adapter 本地连接: 
connection-specific dns suffix . : 
ip address. . . . . . . . . . . . : 10.1.1.94 (本地连接更改之前的ip) 
subnet mask . . . . . . . . . . . : 255.255.255.0 
default gateway . . . . . . . . . : 10.1.1.254 
c:\>netsh (进入设置模式) 
netsh>interface 
interface>ip 
interface ip>set address "本地连接" static 10.1.1.111 255.255.255.0 10.1.1.254 
interface ip>exit 

上文中的set命令具体解释如下:

set address - 设置指定的接口的 ip 地址和默认网关。
set dns - 设置 dns 服务器模式和地址。
set wins - 设置 wins 服务器模式和地址。

c:\>ipconfig (更改后再用ipconfig命令看一下,确认一下是否更改成功) 
windows 2000 ip configuration 
ethernet adapter 本地连接: 
connection-specific dns suffix . : 
ip address. . . . . . . . . . . . : 10.1.1.111 
subnet mask . . . . . . . . . . . : 255.255.255.0 
default gateway . . . . . . . . . : 10.1.1.254 

命令一览

.. - 移到上一层上下文级。
? - 显示命令列表。
aaaa - 更改到 `aaaa` 上下文。
abort - 丢弃在脱机模式下所做的更改。
add - 将一个配置项添加到项目列表中。
alias - 添加一个别名
bye - 退出程序。
commit - 提交在脱机模式中所做的更改。
delete - 在项目列表上删除一个配置项目。
dhcp - 更改到 `dhcp` 上下文。
dump - 显示一个配置脚本。
exec - 运行一个脚本文件。
exit - 退出程序。
help - 显示命令列表。
interface - 更改到 `interface` 上下文。
offline - 将当前模式设置成脱机。
online - 将当前模式设置成联机。
popd - 从堆栈上打开一个上下文。
pushd - 将当前上下文放推入堆栈。
quit - 退出程序。
ras - 更改到 `ras` 上下文。
routing - 更改到 `routing` 上下文。
set - 更新配置设置。
show - 显示信息
unalias - 删除一个别名。
wins - 更改到 `wins` 上下文。

1、全自动修改网络地址:

@echo off 
netsh interface ip set address name="本地连接" static 192.168.1.55 255.255.255.0 192.168.1.1 auto >nul 
netsh interface ip add dns "本地连接" 202.98.96.68 index=1 >nul 
netsh interface ip add dns "本地连接" 61.139.2.69 index=2 >nul 
netsh interface ip set address name="本地连接2" static 192.168.1.55 255.255.255.0 192.168.1.1 auto >nul 
netsh interface ip add dns "本地连接2" 202.98.96.68 index=1 >nul 
netsh interface ip add dns "本地连接2" 61.139.2.69 index=2 >nul 
netsh interface ip set address name="本地连接3" static 192.168.1.55 255.255.255.0 192.168.1.1 auto >nul 
netsh interface ip add dns "本地连接3" 202.98.96.68 index=1 >nul 
netsh interface ip add dns "本地连接3" 61.139.2.69 index=2 >nul 
echo ip地址已经设定修改完毕,按任意键关闭此窗口 
pause >nul 

2、互动修改ip地址

@echo off 
cls 
color 0a 
echo ip地址更改小工具 
set ip=192.168.1.1 
set mask=255.255.255.0 
set gateway=192.168.1.0 
set name="本地连接" 


echo. 
echo 自动更改ip 请按 1 
echo. 
echo 手动更改ip 请按 2 

set /p key= [您的选择是:] 
if %key% == 1 goto one 
if %key% == 2 goto two 

:two 
echo 您选择了手工修改设置。 
echo. 
echo 默认ip地址是%ip%,回车输入默认地址 
set /p ip= [请输入ip地址:] 
echo. 
echo 默认mask是%mask%,回车输入默认值 
set /p mask= [请输入 子网掩码 地址:] 
echo. 
echo 默认gateway是%gateway%,回车输入默认值 
set /p gateway= [请输入 网关 地址:] 
echo. 

:one 
echo 正在自动更改ip...... 
netsh interface ip set address %name% static %ip% %mask% %gateway% 
echo ip地址/子网掩码/网关设置完成 
pause

小说明:

1、第一个之所以要写出 本地连接2 本地连接3,是因为有的机器会因为换网卡或者换驱动造成使用的连接名称为本地连接
2、在xp系统和win7系统下,修改会有一些不同,上面列出的第1个例子多了一个auto,适用于xp,而win7下不能要auto。

软件
前端设计
程序设计
Java相关