0

I'm working on a project in which we create labs (for students) in which users can create virtual machines and specify that they ought to have static ip addresses. The problem is that when a virtual machine is created on Azure, it alwayas has a dynamic ip address and only then can be assigned a static one.

Is there a way to make it possible to allocate multiple simultaneously created virtual machines with static ips that were chosen by users? We do store these ip addresses in the database so before the conflict happens in Azure, we can detect it on the database level but it's not enough.

Why? Because if we create 10 virtual machines at the same time, all of them with specific static ips, some may be created with conflicting dynamic addresses:

  • vm1: dynamic ip - 10.0.0.2, requested static ip 10.0.0.9
  • vm2: dynamic ip - 10.0.0.3, requested static ip 10.0.0.15
  • vm3: dynamic ip - 10.0.0.4, requested static ip 10.0.0.16
  • vm4: dynamic ip - 10.0.0.5, requested static ip 10.0.0.17
  • vm5: dynamic ip - 10.0.0.6, requested static ip ---------
  • vm6: dynamic ip - 10.0.0.7, requested static ip 10.0.0.19
  • vm7: dynamic ip - 10.0.0.8, requested static ip 10.0.0.20
  • vm8: dynamic ip - 10.0.0.9, requested static ip 10.0.0.21
  • vm9: dynamic ip - 10.0.0.10, requested static ip 10.0.0.8
  • vm10: dynamic ip - 10.0.0.11, requested static ip 10.0.0.6

After creation of these vms, when trying to assign 10.0.0.9 to vm1, there will be an error because vm8 has this ip address (although it doesn't want it either, it wants to change to 10.0.0.8 which is taken as well).

I guess a centralized point for creation would be perfect but unless there is something like that on Azure, I don't think it can be done on our end.

Any thoughts?

Aranha
  • 2,903
  • 3
  • 14
  • 29

1 Answers1

1

In the Azure portal, if you use the UI to create VMs directly, a lot of steps will be done by Azure in the backend so that you cannot control the creation. I suggest that you can use the Azure Template or Azure CLI and Azure PowerShell script to achieve it. You can select one of the above three methods. Then you can create the NIC with the Static allocate method.

Charles Xu
  • 29,862
  • 2
  • 22
  • 39
  • Azure Template looks interesting but am I not going to get an address conflict anyway? As far as I understand, templates use Azure REST API under the hood so basically they do what we do, programmatically. Even if 20 VMs are created at the same time and all of them are assigned different ip addresses (manually by user), I expect we still would have ip conflicts because Azure starts VMs with dynamic addresses, beginning at the lowest possible. If one of the VM is manually assigned one of these addresses, there will be a conflict anyway. Am I missing something? – Aranha Dec 28 '20 at 13:39
  • @Aranha First, when you mean static IP addresses, it means you need to calculate the IP addresses and avoid conflict manually. It's the duty of the creator, not the template. You set the static IP addresses, it means you're sure there is no conflict already. – Charles Xu Dec 29 '20 at 01:47
  • That's correct but if I set the IP address to an address that was DYNAMICALLY assigned to another VM (beacuse the template for another VM has not been fully executed yet since it's just a sequence of API calls), there will be a conflict. Am I right here or am I not understanding something correctly? – Aranha Dec 29 '20 at 07:34
  • 1
    @Aranha It's easy to solve. You can create a new VNet that only support your VMs. And as I said, you need to balance the IP yourself, it also means you need to think about the IPs that in use. – Charles Xu Dec 29 '20 at 07:50