#根据连接状态查找使用中网卡
gwmi win32_networkadapter -filter "NetConnectionStatus = 2"
#根据是否配置网关查找使用中网卡
$index = (gwmi Win32_NetworkAdapterConfiguration |?{ $_.DefaultIPGateway -ne $null}).Index
$ConnectionID = (gwmi win32_networkadapter -filter "index = $index").NetConnectionID
$ConnectionID

#查找loopback网卡
$index_lb = (gwmi Win32_NetworkAdapterConfiguration | ? {$_.Description -eq "Microsoft Loopback Adapter"}).index

######################################################################

#禁用/启用网卡

netsh.exe interface set interface "$ConnectionID" disabled
netsh.exe interface set interface "$ConnectionID" enabled

设置静态IP及DNS:

netsh interface ip set address "Wi-Fi" source=static addr=192.168.1.234 mask=255.255.255.0 gateway=192.168.1.2
netsh interface ip set dnsservers "Wi-Fi" static 8.8.8.8 primary validate=no    设置第一个DNS地址

添加多个DNS:

netsh interface ip add dnsservers "Wi-Fi" 202.106.0.20 index=2 validate=no   添加第二个DNS地址(注:如果index=1,则变为第一个DNS地址,原第一个下移)

netsh interface ip add dnsservers "Wi-Fi" 202.106.0.21 index=3 validate=no    添加第三个DNS地址

设置动态IP:

netsh interface ip set address "Wi-Fi" source=dhcp
netsh interface ip set dnsservers "Wi-Fi" source=dhcp

Windows Server 2003:

netsh interface ip set dns "本地连接 4" static 100.40.2.53 primary
netsh interface ip add dns "本地连接 4" 100.40.2.54 index=2
netsh interface ip add dns "本地连接 4" 219.232.48.61 index=5
netsh interface ip add dns "本地连接 4" 202.106.196.115 index=6
ipconfig /all

IP及DNS设置(Netsh)的更多相关文章

  1. centos6.5静态IP和DNS设置

    sudo vi /etc/sysconfig/network-scripts/ifcfg-eth0EVICE=eth0HWADDR=60:02:92:62:30:2ATYPE=EthernetBROA ...

  2. 批处理文件设置IP以及DNS

    先附上批处理文件代码(批处理文件怎么创建自己另行百度,这里不再赘述) Echo offecho ==============请输入序号修改办公区===========echo *********1.家 ...

  3. 利用netsh命令设置IP地址/DNS服务器地址

    一.设置IP地址 1. 自动获取IP地址: netsh interface ip set address [name=]"本地连接" [source=]dhcp 2. 手动设置IP ...

  4. .bat文件设置IP、DNS

    这几天遇到个烦心事,每次开机之后都要去手动去设置一下IP地址,一大串的数字还是有点麻烦,于是就想写个批处理文件设置IP 注意:在DOS下设置IP时需要管理员权限运行 1.查看机子设置IP需要用到的名字 ...

  5. 本地IP,掩码,网关,DNS设置

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  6. windows命令行设置IP与DNS

    用dos命令修改IP等本地连接属性 平时我们改IP通常都在是窗口界面本地连接直接修改, 那在命令行也可以设置IP地址?当然可以,这里要用到netsh命令 .点击“开始”->“运行”,输入“cmd ...

  7. 设置自动获取IP和DNS

    问题阐述 设置ipv4的自动获取时遇到一个问题,ip和dns自动获取可以确认设置,但是全局时就是报错,回头去看ipv4的ip和dns也还是原来的样子 由于一直使用的都是自动获取,很少会有主动设置ip或 ...

  8. Centos6.2设置静态ip和dns

    参考了如下文章:https://gist.github.com/fernandoaleman/2172388http://www.lifelinux.com/how-to-configure-stat ...

  9. Centos 7 安装 设置 IP地址,DNS,主机名,防火墙,端口,SELinux (实测+笔记)

    环境: 系统硬件:vmware vsphere (CPU:2*4核,内存2G,双网卡) 系统版本:CentOS-7.0-1406-x86_64-DVD.iso 安装步骤: 1.虚拟系统安装 1.1 使 ...

随机推荐

  1. Binder 驱动(三)

    Binder 驱动是 Binder 的最终实现, ServiceManager 和 Client/Service 进程间通信最终都是由 Binder 驱动投递的. Binder 驱动的代码位于 ker ...

  2. (转)error while loading shared libraries:libmysqlclient.so.18 错误

    error while loading shared libraries:libmysqlclient.so.18错误 新手安装php的时候如果出现这种问题,解决办法很简单,就是查看你的mysql安装 ...

  3. JS框架设计之加载器所在路径的探知一模块加载系统

    1.要加载一个模块,我们需要一个URL作为加载地址,一个script作为加载媒介,但用户在require是都用ID,我们需要一个将ID转换为URL的方法,思路很简单,强加个约定,URL的合成规则是为: ...

  4. 加载 Firefox 配置

    有小伙伴在用脚本启动浏览器时候发现原来下载的插件不见了,无法用 firebug在打开的页面上继续定位页面元素,调试起来不方便 .加载浏览器配置,需要用 FirefoxProfile(profile_d ...

  5. Ubuntu14.04下完美安装cloudermanage多种方式(图文详解)(博主推荐)

    说在前面的话 我的机器是总共4台,分别为ubuntucmbigdata1.ubuntucmbigdata2.ubuntucmbigdata3和ubuntucmbigdata4. ClouderaMan ...

  6. 卸载oracle10g

    网上搜集的.暂时先用着完全卸载Oracle方法:软件环境: 1.Windows XP + Oracle 10g 2.Oracle安装路径为:d:\Oracle 1.如果数据库配置了自动存储管理(ASM ...

  7. C#中要使ListBox使用AddRange()时,能够触发SelectedValueChanged事件

    1. 要触发 SelectedValueChanged事件,必须要当ListBox所选中的值发生改变 基本思路是: 当AddRange()后,就马上指定ListBox的SelectedIndex,这样 ...

  8. CentOS6.5安装Mysql数据库

    一.卸载原有mysql    # rpm -e --nodeps mysql 二.安装mysql    # yum install mysql-server mysql mysql-devel 三.查 ...

  9. entity framework 查看自动生成的sql

    public MesDbContext() : base("name=mysql") { Database.Log = new Action<string>(msg = ...

  10. C# xml操作word-->word转2003xml

    1.第一步,准备word模版