Create private and public IP addresses
In the previous section, we had a brief look at IP addressing, such as public and private IP addressing and also static and dynamic IP addresses. This section focuses on how to configure private and public IP addresses.
Let's first look at how to configure a private IP address for a VM from dynamic to static via the Azure portal. In order to do this, we are going to reference a VM we created earlier in this book:
- Navigate to the Azure portal by opening a web browser and navigating to https://portal.azure.com.
- In the left menu, select Resource groups and choose an RG with a VM. In this case, we're going to select the Az-104 RG:
- Next, select the VM:
- Under the Settings tab, select Networking and click on the Network Interface Card (NIC) associated with the VM:
- Next, click on IP configurations and select Private IP address:
- Finally, under Assignment, select Static instead of Dynamic, and click Save:
That is how we configure private IP addresses to be static instead of dynamic.
Next, we are going to look at how to create a public IP address via PowerShell:
- In PowerShell, use the following command to connect to our Azure tenant:
Connect-AzAccount
The following screenshot shows the output of the command:
- Next, the following code will create a new static public IP address in the West Europe region as a standard SKU:
$ip = @{
Name = 'myStandardPublicIP'
ResourceGroupName = 'VNet_Demo_ResourceGroup'
Location = 'WestEurope'
Sku = 'Standard'
AllocationMethod = 'Static'
IpAddressVersion = 'IPv4'
Zone = 1,2,3
}
New-AzPublicIpAddress @ip
The following screenshot shows the output of the command:
- Finally, verify that the public IP address has been created in the Azure portal:
It is that simple to create a public IP address via PowerShell. Once the IP address has been created, it is now ready to be assigned to a resource such as a VM or other types of resources that support pre-created public IP addresses.
Next, we are going to look at user-defined routing.