Skip navigation
Add NAT rule to a NIC with AzureRM

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 $<load balancer>.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 "<nic name>"
#Add a NAT Rule to existing NIC
$nic.IpConfigurations[0].LoadBalancerInboundNatRules.Add($NRPLB.InboundNatRules[1]) #Remember NAT rules start at index 0
Set-AzureRmNetworkInterface -NetworkInterface $nic #Update the NIC configuration

 

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish