AWS VPC and Azure VNet are fundamentally different approaches to private networking in the cloud, despite their similar names.

Let’s see what happens when you try to connect an EC2 instance in AWS to a VM in Azure using a site-to-site VPN.

AWS VPC:

Imagine your VPC as a highly configurable, self-contained data center within AWS. You’re in charge of everything from the IP address range (e.g., 10.0.0.0/16) to how traffic flows in and out.

Configuration:

  1. VPC Creation:

    aws ec2 create-vpc --cidr-block 10.0.0.0/16 --tag-specifications 'ResourceType=vpc,Tags=[{Key=Name,Value=MyVPC}]'
    

    This creates a private network with a /16 CIDR block.

  2. Subnet Creation:

    aws ec2 create-subnet --vpc-id vpc-0123456789abcdef0 --cidr-block 10.0.1.0/24 --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=MyPublicSubnet}]'
    

    This carves out a /24 subnet within your VPC. You can have multiple subnets for different availability zones or security zones.

  3. Internet Gateway:

    aws ec2 create-internet-gateway --tag-specifications 'ResourceType=internet-gateway,Tags=[{Key=Name,Value=MyVPC-IGW}]'
    aws ec2 attach-internet-gateway --vpc-id vpc-0123456789abcdef0 --internet-gateway-id igw-0123456789abcdef0
    

    This allows your VPC to communicate with the internet.

  4. Route Table:

    aws ec2 create-route-table --vpc-id vpc-0123456789abcdef0 --tag-specifications 'ResourceType=route-table,Tags=[{Key=Name,Value=MyPublicRouteTable}]'
    aws ec2 create-route --route-table-id rtb-0123456789abcdef0 --destination-cidr-block 0.0.0.0/0 --gateway-id igw-0123456789abcdef0
    aws ec2 associate-route-table --route-table-id rtb-0123456789abcdef0 --subnet-id subnet-0123456789abcdef0
    

    This directs all internet-bound traffic (0.0.0.0/0) through the Internet Gateway.

  5. Security Group:

    aws ec2 create-security-group --group-name MyInstanceSG --description "Security group for my instances" --vpc-id vpc-0123456789abcdef0
    aws ec2 authorize-security-group-ingress --group-id sg-0123456789abcdef0 --protocol tcp --port 22 --cidr 0.0.0.0/0
    

    This acts as a virtual firewall for your instances, controlling inbound and outbound traffic.

Azure VNet:

Azure VNets are more opinionated and designed around a flat IP address space. You define the address space (e.g., 10.1.0.0/16), and then create subnets within it. However, Azure enforces a single, contiguous address space for the entire VNet. You don’t explicitly manage gateways or route tables in the same way; these are often abstracted or managed by services like Azure Load Balancer or Application Gateway.

Configuration:

  1. VNet Creation:

    az network vnet create \
      --resource-group MyResourceGroup \
      --name MyVNet \
      --address-prefixes 10.1.0.0/16
    

    This creates a virtual network with a /16 CIDR block.

  2. Subnet Creation:

    az network vnet subnet create \
      --resource-group MyResourceGroup \
      --vnet-name MyVNet \
      --name MySubnet \
      --address-prefixes 10.1.1.0/24
    

    This creates a /24 subnet within the VNet. Azure requires subnets to be non-overlapping and within the VNet’s address space.

  3. Network Security Group (NSG):

    az network nsg create \
      --resource-group MyResourceGroup \
      --name MyNSG
    az network nsg rule create \
      --resource-group MyResourceGroup \
      --nsg-name MyNSG \
      --name AllowSSH \
      --protocol Tcp \
      --priority 100 \
      --destination-port-range 22 \
      --access Allow \
      --direction Inbound
    az network nic create \
      --resource-group MyResourceGroup \
      --name MyVMNic \
      --vnet-name MyVNet \
      --subnet MySubnet \
      --network-security-group MyNSG
    

    Similar to AWS Security Groups, NSGs act as a stateful firewall. You associate them with network interfaces (NICs) or subnets.

The Core Difference: IP Address Management and Routing

The most significant divergence is how they handle IP addressing and routing. AWS VPC is inherently more granular and flexible. You define individual route tables for subnets, allowing for complex routing scenarios, including custom route tables for different subnets. You can have multiple, non-contiguous CIDR blocks attached to a single VPC, which is a powerful feature for gradual migration or integration.

Azure VNets, while powerful, are designed around a single, contiguous IP address space for the entire VNet. While you can create multiple subnets, they must all fit within the VNet’s primary address prefix. Routing is often managed more implicitly through Azure’s platform services or via User Defined Routes (UDRs) applied at the subnet level, which can feel less direct than AWS’s route tables. For instance, to force traffic through a network virtual appliance (NVA) in Azure, you’d create UDRs on the subnet to point traffic to the NVA’s IP.

When you connect an EC2 instance in VPC 10.0.0.0/16 to a VM in VNet 10.1.0.0/16 using a site-to-site VPN, the crucial part is ensuring these IP ranges don’t overlap. If both your AWS VPC and Azure VNet were configured with 10.0.0.0/16, the VPN tunnel wouldn’t know which traffic belongs to which network, and routing would fail. This is because the VPN gateway on both sides needs to distinguish between local and remote network traffic based on distinct IP address ranges. The VPN device on one side will see traffic from 10.0.0.0/16 and think it’s local, while the other side will also see traffic from 10.0.0.0/16 and think that’s local, leading to routing loops or dropped packets. The fix is always to ensure your VPC CIDR and VNet address space are unique and non-overlapping.

The next challenge you’ll likely encounter is managing DNS resolution between these two distinct cloud environments.

Want structured learning?

Take the full Computer Networking course →