Configure IP Address and DNS from Command Line
来源:互联网 发布:制冷设计软件 编辑:程序博客网 时间:2024/05/18 17:55
之前在使用电脑的时候经常遇到需要手动修改ip地址来实现在局域网和独立端口之间切换的问题,在windows下面这个过程显得比较繁琐,在linux下面我们可以通过新建一个vpn链接来实现过个本地链接,在windows下面不能实现这样的功能,所以便产生了用bat脚本来一键修改本地连接ip地址的想法。
基本信息如下:
@echo off
cls
color 4A
title ip_change
echo IP地址更改小工具
set IP=115.156.219.37
set MASK=255.255.255.224
set GATEWAY=115.156.219.62
set NAME="本地连接"
set IP1=192.168.0.37
set MASK1=255.255.255.0
set GATEWAY1=192.168.0.1
set NAME1="本地连接"
echo.
echo 独立端口 请按 1
echo.
echo 局域网 请按 2
set /p KEY= [您的选择是:]
if %KEY% == 1 goto ONE
if %KEY% == 2 goto TWO
:ONE
echo 正在更改成独立端口......
netsh interface ip set address %NAME% static %IP% %MASK% %GATEWAY%
netsh interface ip add dns %NAME% 202.112.20.131
netsh interface ip add dns %NAME% 202.114.0.242 index=2
echo 更改结束
exit
:TWO
echo 正在更改成局域网ip
netsh interface ip set address %NAME1% static %IP1% %MASK1% %GATEWAY1%
netsh interface ip add dns %NAME1% 202.112.20.131
netsh interface ip add dns %NAME1% 202.114.0.242 index=2
echo 更改结束
exit
====================================分割线=================================================
下面就是netsh用于修改ip信息的相关命令的介绍。
The IP address of your computer can be set from the command prompt by running the following commands at an administrative level prompt:
netsh interface ip set address name="Local Area Connection" static 123.123.123.123 255.255.255.0 123.123.123.1 1
Local Area Connection is the name of the adapter you want to modify. In single NIC systems it is normally called Local Area Connection.
123.123.123.123 is the IP address you want to set.
255.255.255.0 is the subnet mask.
123.123.123.1 is the gateway.
1 is the gateway metric. You can leave this as 1 for almost all cases.
If you want to enable DHCP you can run:
netsh interface ip set address name="Local Area Connection" dhcp
There are two commands for DNS since administrators typically configure a primary and secondary DNS server.
For the primary DNS run:
netsh interface ip set dns name="Local Area Connection" static 208.67.222.222
For the secondary run:
netsh interface ip add dns name="Local Area Connection" 208.67.220.220 index=2
If you want to configure the computer to use DNS from DHCP run:
netsh interface ip set dnsservers name="Local Area Connection" source=dhcp
When you are finished with all of your IP and DNS changes run ipconfig -all to review the new settings.
- Configure IP Address and DNS from Command Line
- How can I get my public IP address from the command line, if I am behind a router?
- ip address & dns
- How to run FTE and FTE from command line
- How to open Firefox and chrome from command line
- DSO missing from command line
- 10 way for configure static IP Address
- Command-line: 解析IP地址
- ImageMagick Tricks: Web Image Effects from the Command Line and PHP
- How to easily open files and URLs from the command line
- Command and Control – DNS
- shell get ip address netmask dns
- Creating a website from the command line
- open .dmg file from command line
- Uninstall DB2 on Linux from Command Line
- Event Configuration from the Command Line
- Process options from command line in BASH
- Creating SQL procedures from the command line
- poj3614 Sunscreen 【优先队列】
- 程序设计实习MOOC/第十三周编程作业/D:滑雪
- 一道笔试题目
- Extjs4的grid列中加上操作的按钮,点击没有选择该行的处理方法
- 初学51单片机几个不易掌握的概念
- Configure IP Address and DNS from Command Line
- Blogger建立Blog部落格 - Blog透视镜
- 成为Java GC专家(5):Java应用性能调优的原则
- Redhat6.3+oracle11G 安装维护
- jsplitpane无法调整大小
- java二维码生成
- MS SQL Server分析数据库的I/O性能
- C++文件复制方法总结
- 注释驱动的 Spring cache 缓存介绍