Isolate and Connect Your Applications with Azure Virtual Networks and Subnets (Part 1)
Tags: azure, cloud, network, security
Published: 2024-07-17 21:56:58

**Introduction:**

Imagine you have a critical application that requires isolation from the public internet and secure communication with other internal resources. Azure virtual networks and subnets provide the perfect solution to achieve this. We'll guide you through creating virtual networks with peered subnets, enabling private and secure communication between your applications.

**Creating the Virtual Networks:**

1. **Search and Create:**  Start by searching for "Virtual Networks" in the Azure portal search bar. Click "Create" to initiate the virtual network creation process.

    ![Clicking Create on Virtual Networks](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a5bexwy1wu6opxprbp4w.jpg)

2. **Resource Group and Naming:** Create a resource group in the East US region to organize your resources. Provide a descriptive name for your virtual network, such as "app-vnet". (The image uses Canada Central, but select East US).

    ![Configure the details for the network](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6kof0vvs14qy5lrnox7m.jpg)

3. **Address Space:** Under the "IP Addresses" tab, define the IPv4 address space for your virtual network. A common private address range is 10.1.0.0/16, which provides a good amount of usable IP addresses.

    ![Changing the default subnet](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kmv9vn8x51xhizul52zq.jpg)

4. **Subnet Configuration:** Click the "Edit" icon for the default subnet. Assign a meaningful name like "frontendSubnet" and configure the address range. Use a subnet mask of /24 (255.255.255.0) to create a subnet with 254 usable IP addresses. For example, you can use the starting IP address 10.1.0.0 for the frontend subnet.  This allocates IP addresses from 10.1.0.0 to 10.1.0.255 for your frontend resources. 

    ![Editing the subnet](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iys0cdoljk55bn807scv.jpg)

5. **Creating the Backend Subnet:** Click "Add a subnet" and configure another subnet named "backendSubnet". Assign a non-overlapping address range within the virtual network's space. For instance, you can use 10.1.1.0/24.

    ![Both subnets](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vq4pdiew9znz35zc8nyh.jpg)

6. **Review and Create:**  Once you've defined both subnets, click "Review + create" to validate and deploy the virtual network.

**Creating the Second Virtual Network:**

Follow steps 1-6 above to create a second virtual network for additional resources or functionalities. Here's an example configuration:
* Resource Group: Use the same resource group 
* Name: Descriptive name, such as "hub-vnet" (for a hub virtual network)
* Address Space: Choose a non-overlapping address space from the available private ranges. For example, you can use 10.0.0.0/16.
* Subnet Configuration: Define subnets specific to the resources you plan to deploy in this virtual network.

![Creating the second virtual network](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ilttq3zciedvahefpc0g.jpg)

**Peering the Virtual Networks:**

1. **Navigate and Select:**  Go to the first virtual network you created and navigate to the "Peerings" section. Click on "Add" to initiate the peering configuration.

    ![Finding Peerings on the first vnet](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8mpmmpo3wo0o67dm1bld.jpg)

2. **Peering Details:**   Provide a descriptive name for the peering connection, such as "app-vnet-to-hub-vnet" (assuming the second network is for a hub).  
3. **Virtual Network Selection:**  Choose the virtual network you want to peer with from the "Virtual network" dropdown menu. In this case, select the second virtual network you just created.
4. **Remote Peering:**  Define a name for the remote peering connection from the target virtual network's perspective. For example, "hub-vnet-to-app-vnet".
5. **Verification:**  Once configured, click "Save" to establish the peering connection. You can then verify the successful peering status in the Azure portal.

![Configuring the peering connection](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/58yfylxskfebes2gdri4.jpg)

![Confirming the peering connection](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3tdmpfo4jzqf9fbjbsp7.jpg)

**Conclusion**

By following these steps, you'll have created isolated virtual networks with subnets for your applications. The peered connection allows secure communication between your frontend and backend resources.