title | description | services | documentationcenter | author | manager | editor | tags | ms.assetid | ms.service | ms.topic | ms.tgt_pltfrm | ms.workload | ms.date | ms.author |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Add network interfaces to or remove from Azure VMs |
Learn how to add network interfaces to or remove network interfaces from virtual machines. |
virtual-network |
na |
mbender-ms |
mtillman |
azure-resource-manager |
virtual-network |
how-to |
na |
infrastructure-services |
03/13/2020 |
mbender |
Learn how to add an existing network interface when you create an Azure virtual machine (VM). Also learn to add or remove network interfaces from an existing VM in the stopped (deallocated) state. A network interface enables an Azure VM to communicate with internet, Azure, and on-premises resources. A VM has one or more network interfaces.
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.
[!INCLUDE updated-for-az]
If you don't have one, set up an Azure account with an active subscription. Create an account for free. Complete one of these tasks before starting the remainder of this article:
-
Portal users: Sign in to the Azure portal with your Azure account.
-
PowerShell users: Either run the commands in the Azure Cloud Shell, or run PowerShell from your computer. The Azure Cloud Shell is a free interactive shell that you can use to run the steps in this article. It has common Azure tools preinstalled and configured to use with your account. In the Azure Cloud Shell browser tab, find the Select environment dropdown list, then pick PowerShell if it isn't already selected.
If you're running PowerShell locally, use Azure PowerShell module version 1.0.0 or later. Run
Get-Module -ListAvailable Az.Network
to find the installed version. If you need to upgrade, see Install Azure PowerShell module. RunConnect-AzAccount
to create a connection with Azure. -
Azure CLI users: Run the commands via either the Azure Cloud Shell the Azure CLI running locally. Use Azure CLI version 2.0.26 or later if you're running the Azure CLI locally. Run
az --version
to find the installed version. If you need to install or upgrade, see Install Azure CLI. Runaz login
to create a connection with Azure.
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. You can't use the portal to add existing network interfaces to a new VM, or to create a VM with multiple network interfaces. You can do both by using the CLI or PowerShell. Be sure to familiarize yourself with the constraints. 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. Learn how to configure Linux or Windows for multiple network interfaces.
Before you create the VM, Create a network interface.
Tool | Command |
---|---|
CLI | az network nic create |
PowerShell | New-AzNetworkInterface |
To add a network interface to your virtual machine:
-
Go to the Azure portal to find an existing virtual machine. Search for and select Virtual machines.
-
Select the name of your VM. The VM must support the number of network interfaces you want to add. To find out how many network interfaces each VM size supports, see the sizes in Azure for Linux VMs or Windows VMs.
-
In the VM command bar, select Stop, and then OK in the confirmation dialog box. Then wait until the Status of the VM changes to Stopped (deallocated).
-
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.
[!NOTE] 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.
-
From the VM menu bar, choose Overview > Start to restart the virtual machine.
Now you can configure the VM operating system to use multiple network interfaces properly. Learn how to configure Linux or Windows for multiple network interfaces.
Tool | Command |
---|---|
CLI | az vm nic add (reference); detailed steps |
PowerShell | Add-AzVMNetworkInterface (reference); detailed steps |
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.
-
Go to the Azure portal to find an existing virtual machine. Search for and select Virtual machines.
[!NOTE] 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.
-
Select the name of the VM for which you want to view attached network interfaces.
-
In the VM menu bar, select Networking.
To learn about network interface settings and how to change them, see Manage network interfaces. To learn about how to add, change, or remove IP addresses assigned to a network interface, see Manage network interface IP addresses.
Tool | Command |
---|---|
CLI | az vm nic list |
PowerShell | Get-AzVM |
-
Go to the Azure portal to find an existing virtual machine. Search for and select Virtual machines.
-
Select the name of the VM for which you want to view attached network interfaces.
-
In the VM toolbar, pick Stop.
-
Wait until the Status of the VM changes to Stopped (deallocated).
-
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.
[!NOTE] 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.
Tool | Command |
---|---|
CLI | az vm nic remove (reference); detailed steps |
PowerShell | Remove-AzVMNetworkInterface (reference); detailed steps |
-
A VM must have at least one network interface attached to it.
-
A VM can only have as many network interfaces attached to it as the VM size supports. 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.
-
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.
-
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. 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. 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. You can now create a VM with any number of network interfaces (up to the number supported by the VM size).
-
By default, the first network interface attached to a VM is the primary network interface. All other network interfaces in the VM are secondary network interfaces.
-
You can control which network interface you send outbound traffic to. 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.
-
In the past, all VMs within the same availability set were required to have a single, or multiple, network interfaces. VMs with any number of network interfaces can now exist in the same availability set, up to the number supported by the VM size. 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.
-
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.
-
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. In the past, only the primary IP address for the primary network interface could be added to a back-end pool. To learn more about IP addresses and configurations, see Add, change, or remove IP addresses.
-
Deleting a VM doesn't delete the network interfaces that are attached to it. When you delete a VM, the network interfaces are detached from the VM. You can add those network interfaces to different VMs or delete them.
-
Achieving the optimal performance documented requires Accelerated Networking. In some cases, you must explicitly enable Accelerated Networking for Windows or Linux virtual machines.
[!INCLUDE ephemeral-ip-note.md]
To create a VM with multiple network interfaces or IP addresses, see:
Task | Tool |
---|---|
Create a VM with multiple NICs | CLI, PowerShell |
Create a single NIC VM with multiple IPv4 addresses | CLI, PowerShell |
Create a single NIC VM with a private IPv6 address (behind an Azure Load Balancer) | CLI, PowerShell, Azure Resource Manager template |