Add NAT rule to a NIC with AzureRM

Add a NAT Rule to expose a port using a load balancer with AzureRM

John Savill

January 15, 2016

1 Min Read
Add NAT rule to a NIC with AzureRM

Q. I have an existing NIC with an Azure ARM VM. How can I add a NAT rule to it?

A. Typically NAT rules are applied to a NIC during the NIC creation, for example:

$nic = New-AzureRmNetworkInterface -Force -Name ('nic' + $vmname) -ResourceGroupName $rgname `    -Location $loc -SubnetId $subnetId -LoadBalancerInboundNatRule $NRPLB.InboundNatRules[0]

 If you want to add a new NAT rule to an existing NIC add a new NAT rule to the load balancer then apply to the existing NIC. To view the existing NAT rules for a load balancer use $.InboundNatRules.

#Add a new rule$NRPLB | Add-AzureRmLoadBalancerInboundNatRuleConfig -Name "RDP2" -FrontendIpConfiguration $frontendIP `    -Protocol TCP -FrontendPort 3442 -BackendPort 3389#Get an object to the NIC to update$nic = Get-AzureRmNetworkInterface -ResourceGroupName $rgName -Name ""#Add a NAT Rule to existing NIC$nic.IpConfigurations[0].LoadBalancerInboundNatRules.Add($NRPLB.InboundNatRules[1]) #Remember NAT rules start at index 0Set-AzureRmNetworkInterface -NetworkInterface $nic #Update the NIC configuration

 

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like