I’m trying to start a ping in Linux VM in Azure. I would like to use API to do that. I have a blank response with status : 202 accepted.
`https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}/runCommand?api-version=2023-07-01
JSON body :
{
"commandId": "RunShellScript",
"script": [
"ping -c 5 8.8.8.8"]
}
I can start and stop my VM with HTTP rest with oauth2.
To make sure it’s not an API error I used "cloud-shell" to run my ping like this :
az vm run-command invoke -g MYRG -n VMname --command-id RunShellScript --scripts "ping -c 5 8.8.8.8"
I get "Running" message for 90 minutes. After I have a timeout.
I opened Outbound port rule : Port 443 Protocol TCP Source Any Destination Any.
Where can be my mistake? It doesn’t work with API or CLI.
Thank you for your help.
3
Answers
Thank you for your comments.
In SSH on the VM, I can ping 8.8.8.8 et do an "ip a".
I tried this command: "az vm run-command invoke -g MYRG -n VMname --command-id RunShellScript --scripts "ip a" in cloud-shell and run-command but just "202 accepted". No answer.
I gonna add the "activity logs" as soon as I have them.
Need to check below:
First, verify that if any firewalls are blocking incoming traffic from the ports you use to connect the virtual machine. This may result in the run command not working as expected.
In your scenario, the ping command may also fail because it uses the Internet Control Message Protocol (ICMP), which cannot enabled by default in Windows Firewall.
Allow it using portal or
New-NetFirewallRule
command.Check the connectivity of the VM routing with below code. Refer attached MS Doc for relevant information.
After checking the above, I tried executing your requirement in my environment with the below CLI command and was able to ping successfully as shown.
You can also check activity logs under virtual machine resource for brief understanding on the error.
Here the output of "Activyty log". Activity log