Windows命令行配置ip地址 |
您所在的位置:网站首页 › 默认网关自动跃点自动改掉 › Windows命令行配置ip地址 |
win + R 可以进入ncpa.cpl
一、添加 IP 地址及默认网关 (是添加,要重设或更新原来IP的请看第三点) netsh interface ip add address用法: add address [name=] [[addr=]IP address [mask=]IP subnet mask] [[gateway=]IP address [gwmetric=]integer] 参数: name IP 接口的名称addr 要添加到此接口的 IP 地址mask IP 地址的 IP 子网掩码gateway IP 地址的默认网关gwmetric 默认网关的跃点数。0 表示自动跃点数
注释 : 向一个用静态 IP 地址配置的接口添加 IP 地址和默认网关。 示例 : add address "本地连接" 172.18.10.197 255.255.255.0 add address "本地连接" gateway=172.18.10.254 gwmetric=2 add address "本地连接" 172.18.10.197 255.255.255.0 172.18.10.254 2 第一个命令向本地连接接口添加一个静态 IP 地址 172.18.10.197 ,子网掩码为 255.255.255.0 。 第二个命令向网关跃点数为 2 的接口添加 IP 地址 172.18.10.254 作为第二个默认网关。 第三个命令是将第一第二个命令合并起来使用。 实例 : netsh interface ip add address "本地连接" 172.18.10.197 255.255.255.0 netsh interface ip add address "本地连接" gateway=172.18.10.254 gwmetric=1 netsh interface ip add address "本地连接" 172.18.10.197 255.255.255.0 172.18.10.254 1 第一个命令设置 本地连接 的 IP 为 172.18.10.197, 子网掩码为 255.255.255.0 第二个命令设置 本地连接 的默认网关为 172.18.10.254, 默认网关的跃点数为 1 第三个命令作用相当于前两条命令的集合。 二、添加 DNS netsh interface ip add dns 用法: add dns [name=] [addr=] [[index=]] 参数: 标记 值 name - 添加 DNS 服务器的接口的名称。 addr - 添加的 DNS 服务器的 IP 地址。 index - 为指定的 DNS 服务器地址指定索引(首选项)。 注释 : 静态添加新的 DNS 服务器 IP 地址或重新索引现有 DNS 服务器地址的列表以修改 DNS 服务器首选项。 示例 : add dns "本地连接" 210.38.176.1 add dns "本地连接" 210.38.176.1 index=2 我的实例: netsh interface ip add dns "本地连接" 210.38.176.1 netsh interface ip add dns "本地连接" 210.38.176.2 index=2 三、设置 IP 地址、默认网关及 DNS 用法: set address [name=] [[source=]dhcp | [source=] static [addr=]IP address [mask=]IP subnet mask] [[gateway=]|none [gwmetric=]integer] 参数: 标记 值 name - 接口名称。 source - 下列值之一: dhcp: 对于指定接口,设置用 DHCP 配置 IP 地址。 static: 设置使用本地静态配置设置 IP 地址。 gateway - 下列值之一: : 您设置的 IP 地址的指定默认网关。 none: 不设置默认网关。 gwmetric - 默认网关的跃点数。如果网关设置为 'none',则不应设置此字段。 只有在 'source' 为 'static' 时才设置下列选项: addr - 指定接口的 IP 地址。 mask - 指定 IP 地址的子网掩码。 注释 : 用来将 IP 地址配置模式从 DHCP 模式改为 static,或从 static模式改为 DHCP。用静态 IP 地址在接口上添加 IP 地址,或添加默认网关。 示例 : netsh interface ip set address "本地连接" static 172.18.10.197 255.255.255.0 netsh interface ip set address "本地连接" static gateway=172.18.10.254 gwmetric=1 netsh interface ip set address "本地连接" static 172.18.10.197 255.255.255.0 172.18.10.254 1 netsh interface ip set dns "本地连接" static 210.38.176.1 (set address source=dhcp 此条表示从 dhcp 服务器得到 IP) (set dns " source=dhcp) 四、综合例 netsh interface ip set address "本地连接" static 172.18.10.197 255.255.255.0 netsh interface ip set address "本地连接" static gateway=172.18.10.254 gwmetric=1 netsh interface ip set dns "本地连接" static 210.38.176.1 netsh interface ip add dns "本地连接" 210.38.176.2 index=2 以上命令做成批处理: edit setIP.bat netsh interface ip set address local static 172.18.10.197 255.255.255.0 netsh interface ip set address local static gateway=172.18.10.254 gwmetric=1 netsh interface ip set dns "%1" static 210.38.176.1 netsh interface ip add dns "%1" 210.38.176.2 index=2
|
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |