0% found this document useful (0 votes)
102 views5 pages

Azure Commands

The document demonstrates how to create a Linux virtual machine in Azure named "my-vm" using the Ubuntu image, configure it with Nginx using a custom script extension, retrieve its public IP address, open port 80 in the network security group to allow HTTP traffic, and verify the Nginx server is reachable via the public IP.

Uploaded by

rajgopalv2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views5 pages

Azure Commands

The document demonstrates how to create a Linux virtual machine in Azure named "my-vm" using the Ubuntu image, configure it with Nginx using a custom script extension, retrieve its public IP address, open port 80 in the network security group to allow HTTP traffic, and verify the Nginx server is reachable via the public IP.

Uploaded by

rajgopalv2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

az vm create \

--resource-group learn-80a1403f-dc8f-4324-8160-250da963b91f \
--name Raj-vm \
--image UbuntuLTS \
--admin-username azureuser \
--generate-ssh-keys

az vm extension set \
--resource-group learn-80a1403f-dc8f-4324-8160-250da963b91f \
--vm-name Raj-vm \
--name customScript \
--publisher Microsoft.Azure.Extensions \
--version 2.1 \
--settings
'{"fileUris":["https://raw.githubusercontent.com/MicrosoftDocs/mslearn-welcome-to-
azure/master/configure-nginx.sh"]}' \
--protected-settings '{"commandToExecute": "./configure-nginx.sh"}'

IPADDRESS="$(az vm list-ip-addresses \
--resource-group [sandbox resource group name] \
--name Raj-vm \
--query "[].virtualMachine.network.publicIpAddresses[*].ipAddress" \
--output tsv)"

From Cloud Shell, run the following az vm create command to create a Linux VM:

Azure CLI

Copy
az vm create \
--resource-group learn-83ed7fe5-18db-40fa-8086-7a072ab4886f \
--name my-vm \
--image UbuntuLTS \
--admin-username azureuser \
--generate-ssh-keys

Your VM will take a few moments to come up. You name the VM my-vm. You use this
name to refer to the VM in later steps.

Run the following az vm extension set command to configure Nginx on your VM:

Azure CLI

Copy
az vm extension set \
--resource-group learn-83ed7fe5-18db-40fa-8086-7a072ab4886f \
--vm-name my-vm \
--name customScript \
--publisher Microsoft.Azure.Extensions \
--version 2.1 \
--settings
'{"fileUris":["https://raw.githubusercontent.com/MicrosoftDocs/mslearn-welcome-to-
azure/master/configure-nginx.sh"]}' \
--protected-settings '{"commandToExecute": "./configure-nginx.sh"}'
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------------------------------
Requesting a Cloud Shell.Succeeded.
Connecting terminal...

Welcome to Azure Cloud Shell

Type "az" to use Azure CLI


Type "help" to learn about Cloud Shell

rgurrapu25 [ ~ ]$ az vm create \
--resource-group learn-83ed7fe5-18db-40fa-8086-7a072ab4886f \
--name my-vm \
--image UbuntuLTS \
--admin-username azureuser \
--generate-ssh-keys
SSH key files '/home/rgurrapu25/.ssh/id_rsa' and '/home/rgurrapu25/.ssh/id_rsa.pub'
have been generated under ~/.ssh to allow SSH access to the VM. If using machines
without permanent storage, back up your keys to a safe location.
Ignite (November) 2023 onwards "az vm/vmss create" command will deploy Gen2-Trusted
Launch VM by default. To know more about the default change and Trusted Launch,
please visit https://aka.ms/TLaD
It is recommended to use parameter "--public-ip-sku Standard" to create new VM with
Standard public IP. Please note that the default public IP used for VM creation
will be changed from Basic to Standard in the future.
Consider using the "Ubuntu2204" alias. On April 30, 2023,the image deployed by the
"UbuntuLTS" alias reaches its end of life. The "UbuntuLTS" will be removed with the
breaking change release of Fall 2023.
{
"fqdns": "",
"id": "/subscriptions/29c214e2-a9dd-4762-9cf7-226d37dc575a/resourceGroups/learn-
83ed7fe5-18db-40fa-8086-7a072ab4886f/providers/Microsoft.Compute/virtualMachines/
my-vm",
"location": "westus",
"macAddress": "60-45-BD-01-54-86",
"powerState": "VM running",
"privateIpAddress": "10.0.0.4",
"publicIpAddress": "20.245.98.36",
"resourceGroup": "learn-83ed7fe5-18db-40fa-8086-7a072ab4886f",
"zones": ""
}
rgurrapu25 [ ~ ]$ az vm extension set \
--resource-group learn-83ed7fe5-18db-40fa-8086-7a072ab4886f \
--vm-name my-vm \
--name customScript \
--publisher Microsoft.Azure.Extensions \
--version 2.1 \
--settings
'{"fileUris":["https://raw.githubusercontent.com/MicrosoftDocs/mslearn-welcome-to-
azure/master/configure-nginx.sh"]}' \
--protected-settings '{"commandToExecute": "./configure-nginx.sh"}'
{
"autoUpgradeMinorVersion": true,
"enableAutomaticUpgrade": null,
"forceUpdateTag": null,
"id": "/subscriptions/29c214e2-a9dd-4762-9cf7-226d37dc575a/resourceGroups/learn-
83ed7fe5-18db-40fa-8086-7a072ab4886f/providers/Microsoft.Compute/virtualMachines/
my-vm/extensions/customScript",
"instanceView": null,
"location": "westus",
"name": "customScript",
"protectedSettings": null,
"protectedSettingsFromKeyVault": null,
"provisioningState": "Succeeded",
"publisher": "Microsoft.Azure.Extensions",
"resourceGroup": "learn-83ed7fe5-18db-40fa-8086-7a072ab4886f",
"settings": {
"fileUris": [
"https://raw.githubusercontent.com/MicrosoftDocs/mslearn-welcome-to-azure/
master/configure-nginx.sh"
]
},
"suppressFailures": null,
"tags": null,
"type": "Microsoft.Compute/virtualMachines/extensions",
"typeHandlerVersion": "2.1",
"typePropertiesType": "customScript"
}
rgurrapu25 [ ~ ]$ IPADDRESS="$(az vm list-ip-addresses \
--resource-group learn-83ed7fe5-18db-40fa-8086-7a072ab4886f \
--name my-vm \
--query "[].virtualMachine.network.publicIpAddresses[*].ipAddress" \
--output tsv)"
rgurrapu25 [ ~ ]$ curl --connect-timeout 5 http://$IPADDRESS
curl: (28) Failed to connect to 20.245.98.36 port 80 after 5001 ms: Timeout was
reached
rgurrapu25 [ ~ ]$ echo $IPADDRESS
20.245.98.36
rgurrapu25 [ ~ ]$ az network nsg list \
--resource-group learn-83ed7fe5-18db-40fa-8086-7a072ab4886f \
--query '[].name' \
--output tsv
my-vmNSG
rgurrapu25 [ ~ ]$ az network nsg rule list \
--resource-group learn-83ed7fe5-18db-40fa-8086-7a072ab4886f \
--nsg-name my-vmNSG
[
{
"access": "Allow",
"destinationAddressPrefix": "*",
"destinationAddressPrefixes": [],
"destinationPortRange": "22",
"destinationPortRanges": [],
"direction": "Inbound",
"etag": "W/\"4f0250c8-6486-4e91-87e1-49ae3cd2dd5d\"",
"id": "/subscriptions/29c214e2-a9dd-4762-9cf7-226d37dc575a/resourceGroups/
learn-83ed7fe5-18db-40fa-8086-7a072ab4886f/providers/Microsoft.Network/
networkSecurityGroups/my-vmNSG/securityRules/default-allow-ssh",
"name": "default-allow-ssh",
"priority": 1000,
"protocol": "Tcp",
"provisioningState": "Succeeded",
"resourceGroup": "learn-83ed7fe5-18db-40fa-8086-7a072ab4886f",
"sourceAddressPrefix": "*",
"sourceAddressPrefixes": [],
"sourcePortRange": "*",
"sourcePortRanges": [],
"type": "Microsoft.Network/networkSecurityGroups/securityRules"
}
]
rgurrapu25 [ ~ ]$ az network nsg rule list \
--resource-group learn-83ed7fe5-18db-40fa-8086-7a072ab4886f \
--nsg-name my-vmNSG \
--query '[].{Name:name, Priority:priority, Port:destinationPortRange,
Access:access}' \
--output table
Name Priority Port Access
----------------- ---------- ------ --------
default-allow-ssh 1000 22 Allow
rgurrapu25 [ ~ ]$ az network nsg rule create \
--resource-group learn-83ed7fe5-18db-40fa-8086-7a072ab4886f \
--nsg-name my-vmNSG \
--name allow-http \
--protocol tcp \
--priority 100 \
--destination-port-range 80 \
--access Allow
{
"access": "Allow",
"destinationAddressPrefix": "*",
"destinationAddressPrefixes": [],
"destinationPortRange": "80",
"destinationPortRanges": [],
"direction": "Inbound",
"etag": "W/\"b3c74937-55f9-4f69-b8b4-7c67e814e1a1\"",
"id": "/subscriptions/29c214e2-a9dd-4762-9cf7-226d37dc575a/resourceGroups/learn-
83ed7fe5-18db-40fa-8086-7a072ab4886f/providers/Microsoft.Network/
networkSecurityGroups/my-vmNSG/securityRules/allow-http",
"name": "allow-http",
"priority": 100,
"protocol": "Tcp",
"provisioningState": "Succeeded",
"resourceGroup": "learn-83ed7fe5-18db-40fa-8086-7a072ab4886f",
"sourceAddressPrefix": "*",
"sourceAddressPrefixes": [],
"sourcePortRange": "*",
"sourcePortRanges": [],
"type": "Microsoft.Network/networkSecurityGroups/securityRules"
}
rgurrapu25 [ ~ ]$ az network nsg rule list \
--resource-group learn-83ed7fe5-18db-40fa-8086-7a072ab4886f \
--nsg-name my-vmNSG \
--query '[].{Name:name, Priority:priority, Port:destinationPortRange,
Access:access}' \
--output table
Name Priority Port Access
----------------- ---------- ------ --------
default-allow-ssh 1000 22 Allow
allow-http 100 80 Allow
rgurrapu25 [ ~ ]$ curl --connect-timeout 5 http://$IPADDRESS
<html><body><h2>Welcome to Azure! My name is my-vm.</h2></body></html>
rgurrapu25 [ ~ ]$
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------------------------------

You might also like