Share via

Error in CLI code for retrieving the private IP

Christian Forjahn 20 Reputation points MVP
2024-11-01T14:57:47.9233333+00:00

Hi,

In the lab https://learn.microsoft.com/en-us/training/modules/control-network-traffic-flow-with-routes/6-exercise-route-traffic-through-nva there is an error in the documentation. I couldn't find out how to contribute to a lab in github.

Here is the error under step 8:

PRIVATEIP="$(az vm list-ip-addresses --resource-group "learn-08a522e5-59b7-49fc-aa72-b99a7020c1bc" --name private --query "[].virtualMachine.network.publicIpAddresses[*].ipAddress" --output tsv)"

echo $PRIVATEIP

This needs to be like that:
PRIVATEIP="$(az vm list-ip-addresses --resource-group "learn-08a522e5-59b7-49fc-aa72-b99a7020c1bc" --name private --query "[].virtualMachine.network.privateAddresses" --output tsv)"

echo $PRIVATEIP

I would be happy if you could tell me how I can contribute to learning paths as this I saw various errors in the past.

Thanks and enjoy the weekend

Chris

This question is related to the following Learning Module

Azure | Azure Training

Answer accepted by question author

VarunTha 14,995 Reputation points Microsoft External Staff Moderator
2024-11-03T06:40:42.4733333+00:00

Hi Christian Forjahn,

Thank you for your feedback and for taking the time to review the documentation! It's great to see your engagement with the learning material, and I appreciate your attention to detail.

Regarding the command in step 8, it is designed to retrieve the public IP address of the specified VM. Here’s a breakdown of the command:

PRIVATEIP="$(az vm list-ip-addresses \
    --resource-group "learn-08a522e5-59b7-49fc-aa72-b99a7020c1bc" \
    --name private \
    --query "[].virtualMachine.network.publicIpAddresses[*].ipAddress" \
    --output tsv)"
    
echo $PRIVATEIP

Explanation:

  • Purpose: This command retrieves the public IP address of the VM named "private" in the specified resource group.
  • Query: The query [].virtualMachine.network.publicIpAddresses[*].ipAddress is designed to extract the public IP addresses assigned to the VM.
  • Output: The result is output as tab-separated values (--output tsv), which is suitable for scripting.

Regarding the Suggested Change:

The suggestion to change the command to retrieve the private IP address instead would look like this:

PRIVATEIP="$(az vm list-ip-addresses \
    --resource-group "learn-08a522e5-59b7-49fc-aa72-b99a7020c1bc" \
    --name private \
    --query "[].virtualMachine.network.privateAddresses" \
    --output tsv)"

echo $PRIVATEIP

Key Differences:

  • The original command retrieves the public IP address, while the suggested command retrieves the private IP address.
  • Depending on the context of the exercise, if the goal is to route traffic through a network virtual appliance (NVA), knowing the private IP address of the VM may be more relevant.

If you encounter any further challenges, please don't hesitate to get in touch with us, and we'll be more than happy to provide additional assistance.

If you have found the answer provided to be helpful, please click on the "Upvote and Accept Answer" button so that it is useful for other members in the Microsoft Q&A community.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.