CMD更改IPv4
本本经常移动,所以每次重新联网的时候需要设置ip,在图形界面下觉得有些麻烦,可以
这样在命令行更改ip:
用管理员(针对win7 和vista)启动CMD
然后>netsh
netsh>interface
netsh interface>ip
netsh interface ipv4>set address "Local Area Connection" static 192.168.2.68 255.255.255.0 192.168.2.254
netsh interface ipv4>exit
不过我可不想每次都这么命令和ip,还是烦;
建立批处理文件 setip.bat
Rem begin
@echo off
echo -------Change Your IP and Gateway-------
echo If you'res sure then press any key or just exit.
pause >nul
set name="Local Area Connection"
Rem dhcp | static
set source="static"
Rem your ipv4 address
set address=192.168.2.68
Rem your mask
set mask=255.255.255.0
Rem your gateway
set gateway=192.168.2.254
Rem Excute the command
echo Now Settting...
echo ip:%address%
echo netmask:%mask%
echo gateway:%gateway%
netsh interface ip set address %name% %source% ^
%address% %mask% %gateway%
echo If no system promption, it success! Or you've to check the configuration.
pause>nul
Rem end
英文的头疼,汉化下:
@echo off
echo -------IP地址修改-------
echo 确定操作请按任意键,否则请退出
pause >nul
set name="本地连接"
Rem dhcp | static
set source="static"
Rem 把address修改为你的ip地址
set address=192.168.2.68
Rem 把mask 修改你你的子网掩码
set mask=255.255.255.0
Rem 把gateway修改为你的网关
set gateway=192.168.2.254
Rem 开始运行命令
echo IP设置中...
echo IPv4地址:%address%
echo 子网掩码:%mask%
echo 网关:%gateway%
netsh interface ip set address %name% %source% ^
%address% %mask% %gateway%
echo 如果没有系统提示额外信息则表示成功,否则请根据系统提示检查错误
pause>nul
以管理员方式运行setip_zh.bat
G:/ipconfig>setipconfig_zh.bat
-------IP地址修改-------
确定操作请按任意键,否则请退出
IP设置中...
IPv4地址:192.168.2.68
子网掩码:255.255.255.0
网关:192.168.2.254
The filename, directory name, or volume label syntax is incorrect.
特别注意,这里出现了错误:原因是我的name不正确,因为我用的是英文版操作系统,
所以name值应该为:Local Area Connection
这样就没错啦;
-------IP地址修改-------
确定操作请按任意键,否则请退出
IP设置中...
IPv4地址:192.168.2.68
子网掩码:255.255.255.0
网关:192.168.2.254
设置批处理我个人认为是非常好的一种方式,当然还有一个选择,根据当前配置制作导出文件,
制作后,你随时可以导入这个文件的配置;
输入命令:
G:/ipconfig>netsh -c interface ip dump
# ----------------------------------
# IPv4 Configuration
# ----------------------------------
pushd interface ipv4
reset
set global icmpredirects=enabled
add route prefix=0.0.0.0/0 interface="Local Area Connection" nexthop=10.136.2.25
4 metric=1 publish=Yes
add address name="Local Area Connection" address=10.136.2.68
# 改dns 可加 :set dns "本地连接8" source=static addr=202.103.44.150
popd
# End of IPv4 configuration
把这段内容保存为ipconfig_cathouse.txt
或者简单的使用重定向符号:>(意思是把输出内容输入到文件,而不是输出到屏幕)
在命令行输入:
netsh -c interface ip dump >ipconfig_cathouse.txt
以后想用的时候就可以导入这个文件,系统会把ip设置为你之前保存在配置文件里的那个;
使用导入命令:
G:/ipconfig>netsh -f ipconfig_cathouse.txt
输出如下结果:
Reseting Global, OK!
Reseting Interface, OK!
Reseting Unicast Address, OK!
Reseting Route, OK!
Restart the computer to complete this action.
The object already exists.
The object already exists.
则一般是成功的;
注意可能不同的操作平台输入结果不一样,但是基本相似;
最后强调,在win7和vista需要使用管理员身份来运行。