Add a Network Interface to an Azure VM

Posted on February 27, 2017 by Russell Smith in Cloud Computing with

In today’s Ask the Admin, I’ll show you how to add a network interface to an Azure virtual machine.

In Configure Multiple NICs in an Azure Virtual Machine on the Petri IT Knowledgebase, I showed you how to provision a virtual machine (VM) with two or more network interfaces (NICs) from the get go. But what if you want to add additional NICs at a later stage? That’s what I’m going to show you how to do today.

 

 

While it’s possible to create NICs in the Azure management portal, it’s not possible to attach them to VMs. That can only be done using PowerShell. So, for the purposes of this article, it makes sense that we do everything in PowerShell. Not all Azure VM sizes support multiple NICs, so make sure you check the size of your VM before trying to add an additional NIC. For more information on VM sizes, see Microsoft’s website here.

Before following the instructions below, you’ll need to have an active Azure subscription. If you don’t already have one, you can sign up for a free trial here. Also, make sure you have the latest version of Microsoft Azure PowerShell installed on your PC. The latest release can be installed using the Web Platform Installer.

Additionally, your VM must already have multiple NICs. A VM with a single NIC cannot be converted into a VM with multiple NICs. That is, if your VM already has two NICs, you can add a third using the method that follows. But if your VM has only one NIC, you cannot add a second. The commands apply to VMs and resources created using Azure Resource Manager and cannot be used for classic VMs.

Sponsored

Create a New NIC and Private IP Address

The first step is to open Windows PowerShell ISE and log in to your Azure subscription using the Login-AzureRmAccount cmdlet. Let’s define some variables for our VM, network, and other parameters that will be required.

$RG defines the Resource Group where the VM and VNET are located. The new NIC will be created in this Resource Group. I picked a name for the new NIC ($nicName), and a private IP address, which I know is available ($ipAddress). If you are not sure what the rest of the values should be for your deployment, locate the VM in the Azure management portal, and you’ll find information about the deployment, network, and any other related resources.

The next step is to create an object for the VM using Get-AzureRmVM:

And now we’ll create an object for the virtual network using Get-AzureRmVirtualNetwork:

The new NIC needs to be connected to a subnet ($subnetName), but we need to know the subnet ID before we can work with it in PowerShell:

Finally, we can create a new NIC using the New-AzureRmNetworkInterface cmdlet:

Add a network interface in Azure (Image Credit: Russell Smith)

Add a network interface in Azure (Image Credit: Russell Smith)

Attach the NIC to a VM

Now that a new NIC has been created, all that’s left to do is to attach it to the VM. First, we’ll create an object for the NIC using the Get-AzureRmNetworkInterface cmdlet:

Let’s add the NIC to the VM configuration:

If you want to check that the configuration has been changed to include the new NIC, you can run the command below to see the list of NICs attached to the VM:

Note that the primary NIC (0) is the first NIC in the list. If you want to set another NIC as the primary NIC, for instance, the third NIC (2), run the command below:

Lastly, let’s commit the new configuration using the Update-AzureRmVM cmdlet:

Attach a network interface to an Azure virtual machine (Image Credit: Russell Smith)

Attach a network interface to an Azure virtual machine (Image Credit: Russell Smith)

In this article, I showed you how to add a NIC to an Azure VM.

Tagged with , , ,

Register for this Webinar

Real World Solutions with Virtual Reality
Free Whitepaper Download

VR is being utilized for a surprising number of vital business functions today. In this white paper, you’ll get an overview of VR technology and see how it’s a vital part of many industries today.

Download the free whitepaper!