Use VM Public IP for Outbound Traffic Instead of NAT Gateway IP

Clive Gerada 1 Reputation point

We have a VM which is in a Subnet associated with a NAT gateway. We have assigned a Public IP to this VM and we can reach it from outside through this public IP. The problem is we need it to use this Public IP also for outbound traffic but it is still using the NAT Gateway public IP.

We have tried restarting the VM. We also don't have any UDR.

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,375 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Alan Kinane 16,796 Reputation points MVP

    The NAT Gateway will take priority here for outbound traffic. See below documentation that confirms.

    I would recommend to move this VM to another subnet on your virtual network and do not associate that subnet with your NAT Gateway. This will route outbound through the IP address.


    0 comments No comments

  2. Clive Gerada 1 Reputation point

    Thanks for the reply. The issue here is the VM was already being used and we already have many other services pointing to it via the private IP. Is there no way to change this behaviour just for this VM and have it retain the same Private IP via Route tables maybe or something?

    Or would it be possible to try adding another interface on another subnet with the Public IP and make that default?

    0 comments No comments

  3. Alan Kinane 16,796 Reputation points MVP

    NAT Gateway always takes precedence so you would need to use another subnet. If your VM supports multiple NICs then yes, you should be able to put add a NIC on another subnet and move the Public IP address there and route outbound through that NIC but note you would want to make this the primary NIC on the VM as otherwise you need to configure outbound routes in your OS.

    0 comments No comments