简体   繁体   English

Azure Power Shell-如何更改网络子网

[英]Azure Power Shell - How to change network subnet

I'm trying to change an existing VM deployed via Resource Manager in Azure. 我正在尝试更改通过Azure中的资源管理器部署的现有VM。 The VM is configured with a wrong VirtualNetwork / Subnet. 虚拟机配置了错误的虚拟网络/子网。 Changing this via portal.azure.net is not possible. 无法通过portal.azure.net更改此portal.azure.net

I've managed to retrieve the required network adapter by running: $adapter = Get-AzureRmNetworkInterface -Name xxxxx -ResourceGroupName xxxxx . 我已经设法通过运行以下命令来检索所需的网络适配器: $adapter = Get-AzureRmNetworkInterface -Name xxxxx -ResourceGroupName xxxxx

I can see the current configured subnet id via $adapter.IpConfigurations.Subnet and I've retrieved the new subnet via $net = Get-AzureRmVirtualNetwork -ResourceGroupName xxxxx -Name xxxxx . 我可以通过$adapter.IpConfigurations.Subnet查看当前配置的子网ID,并且已经通过$net = Get-AzureRmVirtualNetwork -ResourceGroupName xxxxx -Name xxxxx检索了新的子网。

I tried changing the $net.IpConfigurations.Subnet.Id = $net.Subnets.Id but I get a failure : 我尝试更改$net.IpConfigurations.Subnet.Id = $net.Subnets.Id但失败了:

Subnet default referenced by resource xxxx is not the same Virtual Network .... 资源xxxx引用的子网默认不是同一虚拟网络....

Can anybody tell me how to change the virtual network that a network adapter is using if it was deployed using Resource Manager (the "Classic" has the simple Set-Subnet command). 如果使用资源管理器 (“经典”具有简单的Set-Subnet命令)进行部署,谁能告诉我如何更改网络适配器使用的虚拟网络。

Changing the Virtual Network for an exiting ARM deployed VM is not possible. 无法为现有的ARM部署的VM更改虚拟网络。 But, changing the subnet for a VM is quite easy. 但是,更改VM的子网非常容易。

  1. Login the Azure Portal 登录Azure门户
  2. In Resource groups , choose the resource group your VM is in. 在“ 资源组”中 ,选择您的VM所在的资源组。
  3. Choose your VM in the resources list of your resource group. 在资源组的资源列表中选择您的VM。
  4. in Setting blade of your VM, and choose Network Interfaces . 设置 VM的刀片服务器中,然后选择网络接口 在此处输入图片说明
  5. Select the network interface you want to change, and click IP Address . 选择要更改的网络接口,然后单击IP地址 在此处输入图片说明
  6. Choose a Subnet, and specify an IP address, or choose Dynamic Assignment. 选择一个子网,并指定IP地址,或选择“ 动态分配”。 在此处输入图片说明
  7. If none of the exiting subnets meets your requirement, click your Virtual network to create a new subnet. 如果没有一个现有子网满足您的要求,请单击您的虚拟网络以创建一个新子网。 在此处输入图片说明

If you really want to change the Virtual Network of your VM, you can backup your OS Disk, and create a new VM with the OS Disk, and of course with the desired Virtual Network. 如果您确实要更改VM的虚拟网络,则可以备份OS磁盘,并使用OS磁盘(当然还有所需的虚拟网络)创建新的VM。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM