powershell ip_如何使用PowerShell更改IP地址

powershell ip

powershell ip

image

We have already shown you how you can change your IP address from the command prompt, which required long netsh commands, now we are doing the same thing in PowerShell, without the complexity.

我们已经向您展示了如何从命令提示符处更改IP地址 ,这需要很长的netsh命令,现在我们在PowerShell中执行相同的操作,而没有复杂性。

Note: The following commands are new in PowerShell v3 and therefore require Windows 8, they also require an administrative command prompt.

注意:以下命令是PowerShell v3中的新增功能,因此需要Windows 8,它们还需要管理命令提示符。

Editors Note: This article is probably for our more geeky audience and requires some basic knowledge of IP Addressing and CIDR notation

编者注:本文可能是针对我们的极客群读者,并且需要一些IP地址和CIDR表示法的基本知识

更改您的IP地址 (Changing Your IP Address)

We have seen people pulling out their hair trying to change their IP addresses using cryptic WMI classes in older versions of PowerShell, but that changed with PowerShell v3, there is now a NetTCPIP module that brings most of the functionality to native PowerShell. While a bit confusing at first, mostly due to the lack of documentation at the moment, it starts to make sense once the geeks shows you how its done.

我们已经看到人们竭力尝试在旧版PowerShell中使用隐秘WMI类更改IP地址,但是随着PowerShell v3的改变,现在有一个NetTCPIP模块将大多数功能引入了本机PowerShell。 刚开始时有些混乱,主要是由于目前缺少文档,但是一旦极客向您展示了它是如何完成的,它就变得有意义了。

Changing an IP Address can be done using the New-NetIPAddress cmdlet, it has a lot of parameters, some of which, are not even documented in Get-Help. So here it is:

可以使用New-NetIPAddress cmdlet更改IP地址,它具有很多参数,其中一些甚至没有在Get-Help中记录。 所以这里是:

New-NetIPAddress –InterfaceAlias “Wired Ethernet Connection” –IPv4Address “192.168.0.1” –PrefixLength 24 -DefaultGateway 192.168.0.254

New-NetIPAddress –接口别名“有线以太网连接” – IPv4地址“ 192.168.0.1” – PrefixLength 24 -DefaultGateway 192.168.0.254

This assumes the following:

这假定以下条件:

  • The name of the interface you want to change the IP address  for is Local Area Network

    要更改其IP地址的接口的名称是Local Area Network
  • You want to statically assign an IP address of 192.168.0.1

    您要静态分配IP地址192.168.0.1
  • You want to set a subnet mask of 255.255.255.0 (which is /24 in CIDR notation)

    您想要将子网掩码设置为255.255.255.0(在CIDR表示法中为/ 24)
  • You want to set a default gateway of 192.168.0.254

    您想要将默认网关设置为192.168.0.254

You would obviously switch the settings out for some that match the addressing criteria for your network.

显然,您会为某些匹配网络寻址标准的设置进行切换。

设置您的DNS信息 (Setting Your DNS Information)

Now here comes another tricky part, it turns out that there is a whole separate module called DNSClient that you have to use to manipulate your DNS Settings. To change your DNS Server you would use:

现在,这里出现了另一个棘手的部分,事实证明,有一个称为DNSClient的完整独立模块,您必须使用它来操纵DNS设置。 要更改您的DNS服务器,您可以使用:

Set-DnsClientServerAddress -InterfaceAlias “Wired Ethernet Connection” -ServerAddresses 192.168.0.1, 192.168.0.2

Set-DnsClientServerAddress -InterfaceAlias“有线以太网连接” -ServerAddresses 192.168.0.1、192.168.0.2

This assumes that you want to set the primary DNS server for Wired Ethernet Connection to 192.168.0.1 and the secondary DNS server to 192.168.0.2. That’s all there is to it.

假定您要将有线以太网连接的主DNS服务器设置为192.168.0.1,将辅助DNS服务器设置为192.168.0.2。 这里的所有都是它的。

翻译自: https://www.howtogeek.com/112660/how-to-change-your-ip-address-using-powershell/

powershell ip

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值