0
0
Azurecloud~5 mins

Public IP addresses in Azure - Commands & Configuration

Choose your learning style9 modes available
Introduction
Public IP addresses let your cloud resources connect to the internet. They give your virtual machines or services a unique address that anyone on the internet can reach.
When you want your virtual machine to be accessible from the internet for a website or app.
When you need to connect to a cloud service remotely using SSH or RDP.
When you want to assign a fixed internet address to a load balancer.
When you want to expose a container or app running in the cloud to users outside your network.
When you need to test internet connectivity to your cloud resource.
Config File - public-ip.json
public-ip.json
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "resources": [
    {
      "type": "Microsoft.Network/publicIPAddresses",
      "apiVersion": "2022-05-01",
      "name": "myPublicIP",
      "location": "eastus",
      "sku": {
        "name": "Basic"
      },
      "properties": {
        "publicIPAllocationMethod": "Static",
        "idleTimeoutInMinutes": 4,
        "dnsSettings": {
          "domainNameLabel": "myuniquednslabel12345"
        }
      }
    }
  ]
}

This JSON file is an Azure Resource Manager template that creates a public IP address named myPublicIP in the eastus region.

The publicIPAllocationMethod is set to Static so the IP address does not change.

The dnsSettings section assigns a unique DNS label so you can reach the IP by a friendly name.

The idleTimeoutInMinutes controls how long the IP stays open without traffic.

Commands
This command creates a static public IP address named 'myPublicIP' in the 'eastus' region with a DNS label for easy access.
Terminal
az network public-ip create --resource-group myResourceGroup --name myPublicIP --allocation-method Static --location eastus --dns-name myuniquednslabel12345
Expected OutputExpected
{ "dnsSettings": { "domainNameLabel": "myuniquednslabel12345", "fqdn": "myuniquednslabel12345.eastus.cloudapp.azure.com" }, "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Network/publicIPAddresses/myPublicIP", "ipAddress": "52.170.12.34", "ipTags": [], "location": "eastus", "name": "myPublicIP", "publicIPAllocationMethod": "Static", "resourceGroup": "myResourceGroup", "sku": { "name": "Basic" }, "type": "Microsoft.Network/publicIPAddresses" }
--allocation-method - Sets the IP to be static or dynamic
--dns-name - Assigns a DNS label for easier access
--resource-group - Specifies the Azure resource group to use
This command shows details about the public IP address to verify it was created correctly.
Terminal
az network public-ip show --resource-group myResourceGroup --name myPublicIP
Expected OutputExpected
{ "dnsSettings": { "domainNameLabel": "myuniquednslabel12345", "fqdn": "myuniquednslabel12345.eastus.cloudapp.azure.com" }, "id": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myResourceGroup/providers/Microsoft.Network/publicIPAddresses/myPublicIP", "ipAddress": "52.170.12.34", "ipTags": [], "location": "eastus", "name": "myPublicIP", "publicIPAllocationMethod": "Static", "resourceGroup": "myResourceGroup", "sku": { "name": "Basic" }, "type": "Microsoft.Network/publicIPAddresses" }
--resource-group - Specifies the resource group where the IP exists
--name - Specifies the name of the public IP to show
Key Concept

If you remember nothing else from this pattern, remember: a public IP address gives your cloud resource a fixed internet address so others can reach it.

Common Mistakes
Using dynamic allocation when you need a fixed IP
The IP address can change, breaking connections or DNS records.
Always specify --allocation-method Static if you want a permanent IP.
Not specifying a unique DNS label
Without a DNS label, you must use the IP address which is harder to remember and less user-friendly.
Use --dns-name with a unique label to create a friendly DNS name.
Creating the public IP in the wrong resource group or location
Resources may not connect properly if they are in different regions or groups than expected.
Double-check the --resource-group and --location flags to match your deployment.
Summary
Create a public IP address with az network public-ip create to give your resource an internet address.
Use --allocation-method Static to keep the IP fixed and --dns-name for a friendly domain name.
Verify the IP creation with az network public-ip show to see details like the IP address and DNS name.