In this article you will learn setting up a Virtual Machine in Azure portal in a proper way. This method provides a browser-based user interface for creating and configuring virtual machines and all related resources. This Quickstart steps through creating a virtual machine and installing a webserver on the VM.
If you don’t have an Azure subscription, create a free account before you begin.

Understanding the Approach

Before we proceed there are few more things that are important to implement before setting up a virtual machine in azure. First of all we will create a subnet and network security group (NSG) to manage the ports of our virtual machines more conveniently. As illustrated below every virtual machine have its own network security group so we have to manage every machine individually and I believe you wouldn’t want to manage every port and set of IP address for every machine. So here I bring an effective way by surrounding my virtual machines with one subnet and assigning NSG to this subnet to manage all the machines from one point. network security group in azure

If you are still confused then lets consider an example where you have  to open a port 81 of VM1 , port 21 of VM2 and port 25 for VM3 so to achieve this you can either go for typical way by managing subnet and nsg for every machine or can  use my way by putting all the machines under 1 subnet and opening all the ports i.e. 81,21 and 25 from there.

Lets see how we can achieve this:

Creating a VNET

  1. Go to Hamburger Menu of Azure by clicking hamburger icon at top left corner under the logo of azure.
  2. Select New and click networking option.
  3. From the Results choose Virtual Network as shown below
  4. Once you click the virtual network another blade will open telling you the details of vnet with create button at bottom, click it.
  5. creating-vnet-2Now the next blade/screen you will see is of configuration of VNET. The only thing to remember here is the address space and subnet ip range. You can use address space and ip range as as shown in the picture. Make sure you can give any name to your subnet and vnet.
  6. Another important thing here is resource group. Resource group is actually a container for all your resources so for a particular project you can put all its resources i.e. databases, vm, web app etc in one resource group to better manage your resources.
  7. Click the create button and azure will start creating VNET for you.

Creating a Network Security Group

Now we are going to create a network security group that we will apply on our subnet to manage the ports from one point. Lets see how:

  1. Go to Hamburger Menu of Azure by clicking hamburger icon at top left corner under the logo of azure.
  2. Select New and click networking option.
  3. From the Results choose Network security group as shown below:
  4. Now another blade will open asking for little configuration and you can follow the exactly same configuration shown below or can use your own conventions here:
  5. After filling all the required fields and selecting proper resource group just hit the create button.

Assigning Network Security Group to the Subnet

Now its time to assign an nsg to the subnet and lets see how we can do this:

  1. First of all select your vnet and click the subnet option.
  2. Then you have to choose your subnet that will be appearing to you which we created in the beginning as shown below:
  3. When you will select your subnet another blade will open and here you have to assign your subnet as shown below:
  4. Change the network security group from non to the nsg we created in beginning as shown above.

Setting up Windows Virtual Machine in Azure

  1. Click the New button found on the upper left-hand corner of the Azure portal.
  2. Select Compute, select Windows Server 2016 Datacenter, and ensure that Resource Manager is the selected deployment model. Click the Create button.
  3. Enter the virtual machine information. The user name and password entered here is used to log in to the virtual machine. When complete, click OK.
  4. Leave every configuration as it is and just finish the steps and now azure will start creating a Virtual Machine for you.

Connecting A Virtual Machine

At this stage if you download .rdp file for virtual machine it will not allow you to connect as we have to open a port of RDP file i.e. port : 3389 in nsg of subnet and nsg of virtual machine. Lets see how we can do this.

Once your VM is created:

  1. Go to Network Interfaces -> Effective Security Rules.
  2. Here you will see that by default rdp is allowed as shown above but at this time you will still not able to access it because of its prohibition in NSG layer i.e. Front-end-subnet-nsg in my case as shown below:
  3. Now its the time to open rdp access for our virtual machine. At this stage we need to set inbound rules for our network security group (In my case my nsg is front-end-nsg).
  4. On opening the blad of inbound security rules you have to configure with the following details (Name could be any).
  5. That’s all now your VM is ready to connect. Just open your VM blade from azure portal and select connect option.
  6. RDP file will be downloaded and you can access it like I am doing in the following picture:

Benefit of this approach

By this approach you can easily manage all the ports for communication for both publicly as well as in private from one point.

If you found the article helpful, do share or if you have any queries leave a comment.