Search code examples
azurevirtual-machinesubnetvirtual-network

Subnet is not contained within the adress space for the vm


I created a VN of address space 10.1.0.0/16 and a subnet of 10.0.1.0/24. I'm getting the address space error. I tried VN 10.0.0.0/24 and it worked. I wanna know why? Why did the 1st subnet failed and the 2nd passed? How is this address space defined?


Solution

  • Azure virtual networks and subnets use CIDR notation. This allows you to signify the significant bits portion required for networking routing.

    For example, the IPv4 address 192.168.1.0/24 would have netmask of 255.255.255.0, which indicates the first 24 bits are considered significant. This means we couldn't mix two addresses like 192.168.0.0 and 192.168.1.0, since the first 24 bits don't match.

    We can look at the binary representations to make sure:

    • 192.168.0.0 => 11000000 10101000 00000000 00000000
    • 192.168.1.0 => 11000000 10101000 00000001 00000000

    Which shows that the 24th bit don't match between the two IPv4 addresses. We could however change the address space to 192.168.0.0/23, and both addresses would match because the first 23 bits are the same, which also means the netmask would be 255.255.254.0.

    To sum up the above, CIDR gives us more control on how we overlap continuous IP address blocks together.

    Your first virtual network address space of 10.1.0.0/16 needs subnets that share same first 16 bits with netmasks of 255.255.0.0. Subnet address spaces like 10.1.1.0/16 or 10.1.0.0/16 would work here. 10.0.1.0/24 won't work here, since it doesn't overlap with the virtual network address space.

    Your second virtual network address space of 10.0.0.0/24 needs subnets that share the same first 24 bits with netmasks of 255.255.255.0. Subnet address spaces like 10.0.0.1/24 or 10.0.0.2/24 would work here. 10.0.1.0/24 won't work here, since it doesn't overlap with the virtual network address space.

    We can verify the subnet error in the Azure portal when the subnet address space doesn't match the virtual network address space. I've included a screenshot below.

    enter image description here