2.2.9 Configure Network Access
Configuring network access in Azure.
To see current running VMs: az vm list
Task 1: Access your Web Server
Run
az vm list-ip-addressesto get VM IP address, store the result as a BASH variable:
IPADDRESS="$(az vm list-ip-addresses \
--resource-group "GROUP-NAME" \
--name my-vm \
--query "[].virtualMachine.network.publicIpAddresses[*].ipAddress" \
--output tsv)"Run the following
curlcommand to download the homepage:
curl --connect-timeout 5 http://$IPADDRESSAfter 5 seconds, an error message indicates the VM is not accessible. 3. To see the VM IP address, run: echo $IPADDRESS.
Task 2: List Current Network Security Group Rules
Run the following
az network nsg listcommand to list network security groups associated with VM:
az network nsg list \
--resource-group "GROUP-NAME" \
--query "[].name" \
--output tsvEvery VM on Azure is associated with at least one network security group. Azure creates a group for us called my-vmNSG. 2. Run the following az network nsg rule list command to list rules associated with my-vmNSG:
az network nsg rule list \
--resource-group "GROUP-NAME" \
--nsg-name my-vmNSGThis will output a block of JSON text. 3. To make this easier to read, run the following command again but this time using --query and --output to format a table:
az network nsg rule list \
--resource-group "GROUP-NAME" \
--nsg-name my-vmNSG \
--query '[].{Name:name, Priority:priority, Port:destinationPortRange, Access:access}' \
--output tableThe default rule, default-allow-ssh allows inbound connections on port 22. The rule priority is 1000. Rules are processed in order, with lower numbers being processed first. To connect to our web server, we need to allow inbound connections on port 80.
Task 3: Create the Network Security Rule
Run
az network nsg rule createto create a rule called allow-http:
az network nsg rule create \
--resource-group "GROUP-NAME" \
--nsg-name my-vmNSG \
--name allow-http \
--protocol tcp \
--priority 100 \
--destination-port-range 80 \
--access AllowVerify this by running
az network nsg rule list:
az network nsg rule list \
--resource-group "GROUP-NAME" \
--nsg-name my-vmNSG \
--query '[].{Name:name, Priority:priority, Port:destinationPortRange, Access:access}' \
--output tableTask 4: Access the Web Server Again
Run the same
curlcommand again:
curl --connect-timeout 5 http://$IPADDRESSThis should now also work in browser.