How To Attach Network Interface To Azure VM

Attaching a network interface to an Azure VM is a crucial task for the developers to manage the cloud infrastructure. This article discusses two simple approaches to attaching a network interface to your existing Azure Virtual Machine.

Attach Network Interface To Azure VM

Let us dive deep into the approaches individually.

  • Approach-1: Using Azure Portal
  • Approach-2: Using PowerShell

Approach-1: Using Azure Portal

Follow the below steps

1. Log in to the Azure Portal.

2. Search for the virtual machine and click on the search result from Virtual Machines.

add network interface azure vm

3. Select the specific virtual machine from the list of VMs to which you wish to attach the network interface.

attach network interface azure

4. On the Virtual machine page, expand the Networking, click the Networking settings link, and click the Attach network interface button as shown in the screenshot below.

Change network interface Azure VM

Check out How To Detach Network Interface Azure

5. On the attach network interface window, select an existing Azure network interface. Alternatively, click on the Create and attach network interface link to create a new network interface and attach it to the existing VM.

How to attach network interface to Azure VM

If you click on the Create and Attach network interface link, you must fill in the details below.

  • Resource Group: You can select an existing Resource group or click the Create new link to create a new one.
  • Name: Enter a name for your network interface.
  • Subnet: Select a subnet.
  • Public inbound ports: Select none or allow selected ports based on your requirement. If you choose to allow selected ports, you need to select those ports you wish to allow in the Select inbound ports option, as shown in the screenshot below.
associate network interface azure

Based on your requirements, select all other optional options and then click the Create button to create the network interface.

How to change network interface azure vm
How to add network interface azure vm

The new network interface is successfully created and attached to the existing Azure VM.

how to attach network interface to existing azure vm

Now, on the Azure Virtual Machine page, click on the Network settings link. You will see the new network interface attached to the VM successfully. Check out the screenshot below for your reference.

How to change network interface in azure vm

Check out Get-AzVirtualNetworkSubnetConfig

Approach-2: Using PowerShell

You can also use the below PowerShell command to add a network interface to Azure VM.

$myVM = Get-AzVM -ResourceGroupName "newresgroup" -Name "AzureLessonsVM"
Add-AzVMNetworkInterface -VM $myVM -Id "subscriptions/1cdf4300-dee5-4518-9c9c-feaa72a5cbd1/resourceGroups/newresgroup/providers/Microsoft.Network/networkInterfaces/azurelessonsvm908"
Update-AzVM -ResourceGroupName "newresgroup" -VM $myVM

After executing the Azure PowerShell command, you can see that the command was executed successfully and that the new network interface was successfully attached to the Azure VM.

How to attach network interface to Azure VM PowerShell

To cross-check, I just logged in to the Azure portal and verified that the provided Azure network interface has been successfully attached to the existing VM.

How to attach network interface to Azure VM using PowerShell

Conclusion

Attaching network interfaces to Azure VMs is essential to maintaining a robust cloud infrastructure. Using the information mentioned in this article, you can easily achieve this task using Azure Portal and PowerShell.

You may also like following the articles below

Azure Virtual Machine

DOWNLOAD FREE AZURE VIRTUAL MACHINE PDF

Download our free 25+ page Azure Virtual Machine guide and master cloud deployment today!