Add network interfaces to or remove network interfaces from virtual machines

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.

Before you begin

Note

This article has been updated to use the new Azure PowerShell Az module. You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. For Az module installation instructions, see Install Azure PowerShell.

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. Run Connect-AzAccount to create a connection with Azure.

  • Azure Command-line interface (CLI) users: Either run the commands in the Azure Cloud Shell, or run the CLI from your computer. 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. Run az login to create a connection with Azure.

Add existing network interfaces to a new 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. 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.

Commands

Before you create the VM, Create a network interface.

Tool Command
CLI az network nic create
PowerShell New-AzNetworkInterface

Add a network interface to an existing VM

To add a network interface to your virtual machine:

  1. Go to the Azure portal to find an existing virtual machine. Search for and select Virtual machines.

  2. 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.

  3. 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).

  4. 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.

  5. 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.

Commands

Tool Command
CLI az vm nic add (reference); detailed steps
PowerShell Add-AzVMNetworkInterface (reference); detailed steps

View network interfaces for a VM

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.

  1. 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.

  2. Select the name of the VM for which you want to view attached network interfaces.

  3. 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.

Commands

Tool Command
CLI az vm nic list
PowerShell Get-AzVM

Remove a network interface from a VM

  1. Go to the Azure portal to find an existing virtual machine. Search for and select Virtual machines.

  2. Select the name of the VM for which you want to view attached network interfaces.

  3. In the VM toolbar, pick Stop.

  4. Wait until the Status of the VM changes to Stopped (deallocated).

  5. From the VM menu bar, choose Networking > Detach network interface.

  6. 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.

Commands

Tool Command
CLI az vm nic remove (reference); detailed steps
PowerShell Remove-AzVMNetworkInterface (reference); detailed steps

Constraints

  • 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.

Next steps

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