netsh命令

命令:netsh interface ip

1.查看帮助信息

C:/>netsh interface ip /?

下列指令有效:

此上下文中的命令:

?              - 显示命令列表。

add            - 向表中添加一个配置项目。

delete         - 从表中删除一个配置项目。

dump           - 显示一个配置脚本。

help           - 显示命令列表。

reset          - 复位 TCP/IP 及相关的组件到干净的状态。

set            - 设置配置信息。

show           - 显示信息。

2.导出当前配置脚本

C:/>netsh interface ip dump >interface.txt

3.配置IP信息

3.1 添加IP配置信息(add address)

(1)查看帮助信息

netsh interface ip>add address /?

用法: add address [name=]<string> [[addr=]IP address [mask=]IP subnet mask]

       [[gateway=]IP address [gwmetric=]integer]

(2)添加IP、mask、gateway信息

netsh interface ip>add address name="本地连接" addr=192.168.1.123 mask=255.255.2

55.0 gateway=192.168.1.254 gwmetric=1

3.2修改IP配置信息(set address)

(1)查看帮助信息

netsh interface ip>set address /?

用法: set address [name=]<string>

       [[source=]dhcp |

        [source=] static [addr=]IP address [mask=]IP subnet mask]

       [[gateway=]<IP address>|none [gwmetric=]integer]

(2)静态设置IP

完整命令:

①netsh interface ip>set address name="本地连接" source=static addr=211.67.17.120

mask=255.255.255.0 gateway=211.67.17.254 gwmetric=1

当然,name=、source=、addr=、mask=、gateway=、gwmetric= 可以省略,写成如下形式(必须按照顺序)

②netsh interface ip>set address "本地连接" static 211.67.17.120 255.255.255.0 211

.67.17.254 1

也可以写成如下形式:

③netsh interface ip>set address "本地连接" static 211.67.17.120 255.255.255.0

④netsh interface ip>set address name="本地连接" source=static addr=211.67.17.123

mask=255.255.255.0

⑤netsh interface ip>set address "本地连接" static gateway=211.67.17.254 gwmetric=1

其中,③④是等价的,⑤必须写上gateway=、 gwmetric=之类的

建议:最好将“name=、source=、addr=、mask=、gateway=、gwmetric=”等都写上,这样一目了然,不容易出错。

(3)动态设置IP

netsh interface ip>set address name="本地连接" source=dhcp

3.3删除IP配置信息(delete address)

(1)查看帮助信息

netsh interface ip>delete address /?

用法: delete address [name=]<string> [[addr=]IP address] [[gateway=]IP address|ALL]

(2) 删除网关信息

netsh interface ip>delete address name="本地连接" gateway=192.168.1.254

注:没有使用 DHCP 的界面必须有一个或多个静态 IP 地址。

4.配置DNS信息

4.1添加DNS(add dns)

(1)查看帮助信息

netsh interface ip>add dns

用法: add dns [name=]<string> [addr=]<IP address> [[index=]<integer>]

(2)添加DNS

①netsh interface ip>add dns name="本地连接" addr=202.114.0.242

②netsh interface ip>add dns name="本地连接" addr=202.114.0.242 index=1

若还未设置DNS,①②功能是一样的,都是将202.114.0.242设为首选DNS服务器

③设置辅助DNS服务器

netsh interface ip>add dns name="本地连接" addr=202.112.30.131 index=2

注:默认情况下,新添加的DNS 服务器被添加在列表的结尾

4.2设置DNS(set dns)

(1)查看帮助信息

netsh interface ip>set dns /?

用法: set dns [name=]<string> [source=]dhcp|static [addr=]<IP address>|none

             [[register=]none|primary|both]

(2)设置DNS

netsh interface ip>set dns name="本地连接" source=static addr=202.114.0.242 register=primary

4.3删除DNS(delete dns)

(1) 查看帮助信息

netsh interface ip>delete dns /?

用法: delete dns [name=]<string> [[addr=]<IP address>|ALL ]

(2)删除DNS

①删除指定DNS

netsh interface ip>delete dns name="本地连接" addr=202.114.0.242

注:若删除首选DNS,则原先辅助DNS变为当前首选DNS

②删除所有DNS:netsh interface ip>delete dns name="本地连接" addr=all

绑定到某IP: httpcfg set iplisten -i 192.168.0.1  
查看绑定IP: httpcfg query iplisten 
删除绑定IP: httpcfg delete iplisten -i 192.168.0.1

可是windows server 2012没有httpcfg该怎么办呢,还真被我想到办法了,废话不多说直接入正题,因为我想睡觉了:

先是CMD下输入下列命令,然后回车

netsh http show iplisten

果然ECS迁移之前的IP存在这个侦听列表中。那么简单了,用下面这个命令删除

netsh http delete iplisten ipaddress=迁移前的IP
原文地址:https://www.cnblogs.com/Li-yuan/p/10601296.html