Assigning multiple IPs to Windows VM in Azure
There are times when VM in Azure needs to have more than one IP address. It can be just secondary IP for specific service running on VM, or IP-address of load balancer that is attached to.
There are couple of (well documented) ways this can be configured on Azure end, and several ways to configure OS end.
When multiple IP addresses configured in Azure, the primary can be assigned via DHCP, however, that's a challenging task part to assign 2nd and subsequent IPs to VM.
Here I am exploring the new way that can be simple enough and effective at the same time.
Azure configuration.
- assign 2nd (and all the subsequent, up to 200) IP address as a secondary IP
- use Attach Load Balancer to VM, and enable Floating IP (otherwise Load Balancer will use NIC IP, instead of LB IP)
Windows configuration.
Loopback Interface
- Very well known way of configuring IPs on Windows VMs
- Requires manual installation of Loopback Adapter (automatic installation is also possible, but requires downloading/installing external Microsoft tool, that does not have any persistent link)
- Requires configuring relaxed routing configuration on NICs, that allows traffic destined to one nic, be received on another one.
Static NIC configuration
- Another widely used and accepted option.
- Easy to automate without any external tools (powershell / netsh)
- Easy to lose access to the VM, in case of misconfiguration or sudden IP address change.
DHCP + Static configuration coexistence on the same NIC:
Very few mentions of this approach in the Internet at all, and I haven't seen or faced anybody used that approach in Azure at all.
This option, available since "Windows Server 2019/20 / Windows 10 2xHx" seems to change the game: It allows VM to have Primary IP of each NIC to be configured as dynamic via DHCP, and all the subsequent IPs - as static.
Get the interface name to use on the next steps
- netsh interface ipv4 show interface
- netsh interface ipv4 set interface interface="interface name" dhcpstaticipcoexistence=enabled
- netsh interface ipv4 add address "interface name" 192.168.x.xxx 255.255.255.0
- Uses the built-in Windows Tools
- In case of Misconfiguration, IP address change, or reconfiguration, preserves access to VM via Primary (DHCP) IP address.
- This option works perfectly fine on Windows laptops and Servers outside Azure
- Works only on Windows 2019+/Windows 10+
- Turning the option on requires netsh, cannot be done with PowerShell
- GUI cannot be used to configure the IP addresses. Interface will seem to be using only DHCP, and will not display static IPs.
Example
Here how it looks like in my lab VM:
- Primary DHCP IP,
- Two secondary static IPs
- Public Load Balancer Floating IP configured
Userful Links
NetSh interface: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/netsh-interface
Azure: Configure VM with multiple IPs (static) https://learn.microsoft.com/en-us/azure/virtual-network/ip-services/virtual-network-multiple-ip-addresses-portal#windows-server
Azure: Configuring Load Balancer Floating IP: https://learn.microsoft.com/en-us/azure/load-balancer/load-balancer-floating-ip
Comments
Post a Comment