linux虚拟网络接口删除,向 Azure VM 添加网络接口或从中删除网络接口 | Microsoft Docs...

您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

在虚拟机中添加或删除网络接口。Add network interfaces to or remove network interfaces from virtual machines

03/13/2020

本文内容

了解在创建 Azure 虚拟机 (VM) 时如何添加现有的网络接口。Learn how to add an existing network interface when you create an Azure virtual machine (VM). 还将了解如何在现有 VM 中添加或删除处于已停止(已解除分配)状态的网络接口。Also learn to add or remove network interfaces from an existing VM in the stopped (deallocated) state. Azure VM 通过网络接口与 Internet、Azure 及本地资源通信。A network interface enables an Azure VM to communicate with internet, Azure, and on-premises resources. VM 有一个或多个网络接口。A VM has one or more network interfaces.

如果需要为网络接口添加、更改或删除 IP 地址,请参阅管理网络接口 IP 地址。If you need to add, change, or remove IP addresses for a network interface, see Manage network interface IP addresses. 若要创建、更改或删除网络接口,请参阅管理网络接口。To create, change, or delete network interfaces, see Manage network interfaces.

准备阶段Before you begin

备注

本文已经过更新,以便使用 Azure Az PowerShell 模块。This article has been updated to use the Azure Az PowerShell module. 若要与 Azure 交互,建议使用的 PowerShell 模块是 Az PowerShell 模块。The Az PowerShell module is the recommended PowerShell module for interacting with Azure. 若要开始使用 Az PowerShell 模块,请参阅安装 Azure PowerShell。To get started with the Az PowerShell module, see Install Azure PowerShell. To learn how to migrate to the Az PowerShell module, see Migrate Azure PowerShell from AzureRM to Az.

如果你没有 Azure 帐户,请使用有效的订阅设置一个帐户。If you don't have one, set up an Azure account with an active subscription. 在开始学习本文的余下内容之前,请完成以下任务之一:Complete one of these tasks before starting the remainder of this article:

门户用户:使用 Azure 帐户登录到 Azure 门户。Portal users: Sign in to the Azure portal with your Azure account.

PowerShell 用户:在 Azure Cloud Shell 中运行命令,或在计算机上运行 PowerShell。PowerShell users: Either run the commands in the Azure Cloud Shell, or run PowerShell from your computer. Azure Cloud Shell 是免费的交互式 shell,可以使用它运行本文中的步骤。The Azure Cloud Shell is a free interactive shell that you can use to run the steps in this article. 它预安装有常用 Azure 工具并将其配置与帐户一起使用。It has common Azure tools preinstalled and configured to use with your account. 在 Azure Cloud Shell 浏览器标签页中,找到“选择环境”下拉列表,然后选择“PowerShell”(如果尚未选择) 。In the Azure Cloud Shell browser tab, find the Select environment dropdown list, then pick PowerShell if it isn't already selected.

如果在本地运行 PowerShell,请使用 Azure PowerShell 模块 1.0.0 或更高版本。If you're running PowerShell locally, use Azure PowerShell module version 1.0.0 or later. 运行 Get-Module -ListAvailable Az.Network 查找已安装的版本。Run Get-Module -ListAvailable Az.Network to find the installed version. 如果需要进行升级,请参阅 Install Azure PowerShell module(安装 Azure PowerShell 模块)。运行 Connect-AzAccount,创建与 Azure 的连接。Run Connect-AzAccount to create a connection with Azure.

Azure 命令行接口 (CLI) 用户:在 Azure Cloud Shell 中运行命令,或在计算机中运行 CLI。Azure Command-line interface (CLI) users: Either run the commands in the Azure Cloud Shell, or run the CLI from your computer. 如果在本地运行 Azure CLI,请使用 Azure CLI 2.0.26 或更高版本。Use Azure CLI version 2.0.26 or later if you're running the Azure CLI locally. 运行 az --version 查找已安装的版本。Run az --version to find the installed version. 如果需要进行安装或升级,请参阅安装 Azure CLI。If you need to install or upgrade, see Install Azure CLI. 运行 az login,创建与 Azure 的连接。Run az login to create a connection with Azure.

将现有网络接口添加到新 VMAdd existing network interfaces to a new VM

通过门户创建虚拟机时,门户会使用默认设置创建一个网络接口,并将其附加到 VM。When you create a virtual machine through the portal, the portal creates a network interface with default settings and attaches the network interface to the VM for you. 无法使用门户将现有网络接口添加到新的 VM,或创建具有多个网络接口的 VM。You can't use the portal to add existing network interfaces to a new VM, or to create a VM with multiple network interfaces. 可以使用 CLI 或 PowerShell 执行这两项操作。You can do both by using the CLI or PowerShell. 请确保熟悉约束。Be sure to familiarize yourself with the constraints. 如果要创建具有多个网络接口的 VM,还必须将操作系统配置为在创建 VM 后正确使用它们。If you create a VM with multiple network interfaces, you must also configure the operating system to use them properly after you create the VM. 了解如何将 Linux 或 Windows 配置为使用多个网络接口。Learn how to configure Linux or Windows for multiple network interfaces.

命令Commands

在创建 VM 之前,请创建网络接口。Before you create the VM, Create a network interface.

将网络接口添加到现有 VMAdd a network interface to an existing VM

若要向虚拟机添加网络接口,请执行以下操作:To add a network interface to your virtual machine:

转到 Azure 门户来查找现有虚拟机。Go to the Azure portal to find an existing virtual machine. 搜索并选择“虚拟机”。Search for and select Virtual machines.

选择你的 VM 的名称。Select the name of your VM. 该 VM 必须支持要添加的网络接口的数量。The VM must support the number of network interfaces you want to add. 若要了解每个 VM 大小支持的网络接口数量,请参阅 Azure 中适用于 Linux VM 或 Windows VM 的大小。To find out how many network interfaces each VM size supports, see the sizes in Azure for Linux VMs or Windows VMs.

在 VM 命令栏中,选择“停止”,然后在确认对话框中选择“确定”。In the VM command bar, select Stop, and then OK in the confirmation dialog box. 然后,等待 VM 的“状态”更改为“已停止(已解除分配)” 。Then wait until the Status of the VM changes to Stopped (deallocated).

从 VM 菜单栏中,选择“网络” > “附加网络接口”。From the VM menu bar, choose Networking > Attach network interface. 然后,在“附加现有网络接口”中,选择要附加的网络接口,并选择“确定”。Then in Attach existing network interface, choose the network interface you'd like to attach, and select OK.

备注

选择的网络接口无法启用加速网络,无法获得 IPv6 地址,并且必须位于包含当前附加到 VM 的网络接口的虚拟网络中。The network interface you select can't have accelerated networking enabled, can't have an IPv6 address assigned to it, and must exist in the same virtual network with the network interface currently attached to the VM.

如果没有现有的网络接口,必须先创建一个。If you don't have an existing network interface, you must first create one. 为此,请选择“创建网络接口”。To do so, select Create network interface. 若要详细了解如何创建网络接口,请参阅创建网络接口。To learn more about how to create a network interface, see Create a network interface. 若要详细了解将网络接口添加到虚拟机时的约束,请参阅约束。To learn more about additional constraints when adding network interfaces to virtual machines, see Constraints.

从 VM 菜单栏中,选择“概览” > “启动”来重启虚拟机。From the VM menu bar, choose Overview > Start to restart the virtual machine.

现在,你可以配置 VM 操作系统以正确地使用多个网络接口。Now you can configure the VM operating system to use multiple network interfaces properly. 了解如何将 Linux 或 Windows 配置为使用多个网络接口。Learn how to configure Linux or Windows for multiple network interfaces.

命令Commands

查看 VM 的网络接口View network interfaces for a VM

可以查看当前附加到 VM 的网络接口,了解每个网络接口的配置,以及分配给每个网络接口的 IP 地址。You can view the network interfaces currently attached to a VM to learn about each network interface's configuration, and the IP addresses assigned to each network interface.

转到 Azure 门户来查找现有虚拟机。Go to the Azure portal to find an existing virtual machine. 搜索并选择“虚拟机”。Search for and select Virtual machines.

备注

使用分配有订阅“所有者”、“参与者”或“网络参与者”角色的帐户登录。Sign in using an account that is assigned the Owner, Contributor, or Network Contributor role for your subscription. To learn more about how to assign roles to accounts, see Built-in roles for Azure role-based access control.

选择你要查看其附加的网络接口的 VM 的名称。Select the name of the VM for which you want to view attached network interfaces.

在 VM 菜单栏中,选择“网络”。In the VM menu bar, select Networking.

若要了解网络接口的设置及其更改方法,请参阅管理网络接口。To learn about network interface settings and how to change them, see Manage network interfaces. 若要了解如何添加、更改或删除分配到网络接口的 IP 地址,请参阅管理网络接口 IP 地址。To learn about how to add, change, or remove IP addresses assigned to a network interface, see Manage network interface IP addresses.

命令Commands

从 VM 中删除网络接口Remove a network interface from a VM

转到 Azure 门户来查找现有虚拟机。Go to the Azure portal to find an existing virtual machine. 搜索并选择“虚拟机”。Search for and select Virtual machines.

选择你要查看其附加的网络接口的 VM 的名称。Select the name of the VM for which you want to view attached network interfaces.

在 VM 工具栏中,选择“停止”。In the VM toolbar, pick Stop.

等到 VM 的“状态”更改为“已停止(已解除分配)” 。Wait until the Status of the VM changes to Stopped (deallocated).

从 VM 菜单栏中,选择“网络” > “分离网络接口”。From the VM menu bar, choose Networking > Detach network interface.

在“分离网络接口”对话框中,选择要分离的网络接口。In the Detach network interface dialog box, select the network interface you'd like to detach. 然后选择“确定”。Then select OK.

备注

如果只列出了一个网络接口,则无法将它分离,因为虚拟机上必须始终至少附加一个网络接口。If only one network interface is listed, you can't detach it, because a virtual machine must always have at least one network interface attached to it.

命令Commands

约束Constraints

VM 上必须至少附加一个网络接口。A VM must have at least one network interface attached to it.

VM 上附加的网络接口数量不能超过 VM 大小支持的数量。A VM can only have as many network interfaces attached to it as the VM size supports. 若要详细了解每个 VM 大小支持的网络接口数量,请参阅 Azure 中适用于 Linux VM 或 Windows VM 的大小。To learn more about how many network interfaces each VM size supports, see the sizes in Azure for Linux VMs or Windows VMs. 所有大小至少支持两个网络接口。All sizes support at least two network interfaces.

目前,添加到一个 VM 的网络接口不能附加到另一个 VM。The network interfaces you add to a VM can't currently be attached to another VM. 若要详细了解如何创建网络接口,请参阅创建网络接口。To learn more about how to create network interfaces, see Create a network interface.

过去,只能向支持多个网络接口且至少是使用两个网络接口创建的 VM 中添加网络接口。In the past, you could add network interfaces only to VMs that supported multiple network interfaces and were created with at least two network interfaces. 不能向使用一个网络接口创建的 VM 添加网络接口,即使 VM 大小支持多个网络接口。You couldn't add a network interface to a VM that was created with one network interface, even if the VM size supported more than one network interface. 相反,只能从至少有三个网络接口的 VM 中删除网络接口,因为使用至少两个网络接口创建的 VM 必须始终有至少两个网络接口。Conversely, you could only remove network interfaces from a VM with at least three network interfaces, because VMs created with at least two network interfaces always had to have at least two network interfaces. 这些约束将不再应用。These constraints no longer apply. 现在,可以创建包含任意数量(但不能超过 VM 大小支持的数量)的网络接口的 VM。You can now create a VM with any number of network interfaces (up to the number supported by the VM size).

默认情况下,VM 上附加的第一个网络接口是主网络接口。By default, the first network interface attached to a VM is the primary network interface. VM 中的所有其他网络接口为辅助网络接口。All other network interfaces in the VM are secondary network interfaces.

你可以控制要将出站流量发送到的网络接口。You can control which network interface you send outbound traffic to. 但是,VM 默认情况下会将所有出站流量都发送到分配给主网络接口的主 IP 配置的 IP 地址。However, a VM by default sends all outbound traffic to the IP address that's assigned to the primary IP configuration of the primary network interface.

过去,同一个可用性集中的所有 VM 都需要有一个或多个网络接口。In the past, all VMs within the same availability set were required to have a single, or multiple, network interfaces. 现在,同一个可用性集中可以存在具有任意数目的网络接口的 VM,只要 VM 大小支持该数目。VMs with any number of network interfaces can now exist in the same availability set, up to the number supported by the VM size. 只能在创建 VM 时将其添加到可用性集。You can only add a VM to an availability set when it's created. To learn more about availability sets, see Manage the availability of VMs in Azure.

可以将同一 VM 中的网络接口连接到虚拟网络中的不同子网。You can connect network interfaces in the same VM to different subnets within a virtual network. 但是,网络接口必须全部连接到同一个虚拟网络。However, the network interfaces must all be connected to the same virtual network.

可将任何主要或辅助网络接口的任何 IP 配置的任何 IP 地址添加到 Azure 负载均衡器后端池。You can add any IP address for any IP configuration of any primary or secondary network interface to an Azure Load Balancer back-end pool. 过去,只能将主要网络接口的主要 IP 地址添加到后端池。In the past, only the primary IP address for the primary network interface could be added to a back-end pool. 若要详细了解 IP 地址和配置,请参阅添加、更改或删除 IP 地址。To learn more about IP addresses and configurations, see Add, change, or remove IP addresses.

删除 VM 不会删除附加到它的网络接口。Deleting a VM doesn't delete the network interfaces that are attached to it. 删除 VM 时,网络接口将与该 VM 分离。When you delete a VM, the network interfaces are detached from the VM. 可将那些网络接口添加到不同的 VM,也可将其删除。You can add those network interfaces to different VMs or delete them.

若要实现所记录的最佳性能,需要使用“加速网络”。Achieving the optimal performance documented requires Accelerated Networking. 在某些情况下,必须为 Windows 或 Linux 虚拟机显式启用“加速网络”。In some cases, you must explicitly enable Accelerated Networking for Windows or Linux virtual machines.

备注

Azure 为未获得公共 IP 地址或位于内部基本 Azure 负载均衡器后端池中的 Azure 虚拟机提供临时 IP。Azure provides an ephemeral IP for Azure Virtual Machines which aren't assigned a public IP address, or are in the backend pool of an internal Basic Azure Load Balancer. 临时 IP 机制可提供无法配置的出站 IP 地址。The ephemeral IP mechanism provides an outbound IP address that isn't configurable.

如果将公共 IP 地址分配给某个虚拟机或将该虚拟机置入具有或不具有出站规则的标准负载均衡器的后端池中时,将禁用其原有的临时 IP。The ephemeral IP is disabled when a public IP address is assigned to the virtual machine or the virtual machine is placed in the backend pool of a Standard Load Balancer with or without outbound rules. 如果向虚拟机的子网分配 Azure 虚拟网络 NAT 网关资源,也会禁用其临时 IP。If a Azure Virtual Network NAT gateway resource is assigned to the subnet of the virtual machine, the ephemeral IP is disabled.

后续步骤Next steps

若要创建具有多个网络接口或 IP 地址的 VM,请参阅:To create a VM with multiple network interfaces or IP addresses, see:

任务Task

工具Tool

创建具有多个 NIC 的 VMCreate a VM with multiple NICs

创建具有多个 IPv4 地址的单 NIC VMCreate a single NIC VM with multiple IPv4 addresses

创建具有专用 IPv6 地址的单 NIC VM(在 Azure 负载均衡器后)Create a single NIC VM with a private IPv6 address (behind an Azure Load Balancer)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值