How to add a Secondary NIC on a VM in Azure
===================================
I have a Virtual Machine named sqlnode1 and it is on ResourceGroupName rakctlrg
The Virtual Machine has a NIC interface whose IP address is 10.0.0.4
The customer comes and say that they want to add a Extra NIC on the server.
How we will add a Extra NIC on the server.
Below is the Step by Step process to ADD a Secondary NIC on the server.
======================================================
1. Go to shell.azure.com
2. login to shell.azure.com
#First store the Azure VM in the a $VM variable
$vm = Get-AzureRmVm -Name "sqlnode1" -ResourceGroupName "rakctlrg"
#Make existing NIC as a Priamry NIC.
================================
$VM.NetworkProfile.NetworkInterfaces.Item(0).primary = $true
Update-AzureRmVM -ResourceGroupName "rakctlrg" -VM $VM
# Get info for the back end subnet
$myVnet = Get-AzureRmVirtualNetwork -Name "rakctlrg-vnet" -ResourceGroupName "rakctlrg"
$backEnd = $myVnet.Subnets|?{$_.Name -eq 'default'}
# Create a virtual NIC
====================
$myNic3 = New-AzureRmNetworkInterface -ResourceGroupName "rakctlrg" `
-Name "myNic3" `
-Location "centralus" `
-SubnetId $backEnd.Id
# Get the ID of the new virtual NIC and add to VM
$nicId = (Get-AzureRmNetworkInterface -ResourceGroupName "rakctlrg" -Name "MyNic3").Id
Before executing below command, you need to stop the VM.
Then execute the below command
#Add a AzureRMVMNetworkInterface
=============================
Add-AzureRmVMNetworkInterface -VM $vm -Id $nicId | Update-AzureRmVm -ResourceGroupName "rakctlrg"
Then start the VM, you will find one more NIC in the server.
you will observe one extra NIC has been added in Azure VM.
Important point to remember:-
=======================
1. VM should be in deallocated state.
2. we can add multiple NIC in a VM, but it depends on the size of VM, example D2s v3 can support maximum of 2 NIC.
3. when adding 2nd NIC, first NIC should be on primary NIC.
Thanks for Reading..