skip to Main Content

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


  1. Chosen as BEST ANSWER

    Thank you for your comments.

    In SSH on the VM, I can ping 8.8.8.8 et do an "ip a".

    ........@Linux1:~$ ping 8.8.8.8
    PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
    64 bytes from 8.8.8.8: icmp_seq=1 ttl=112 time=8.10 ms
    64 bytes from 8.8.8.8: icmp_seq=2 ttl=112 time=8.37 ms
    64 bytes from 8.8.8.8: icmp_seq=3 ttl=112 time=8.19 ms
    64 bytes from 8.8.8.8: icmp_seq=4 ttl=112 time=8.10 ms
    64 bytes from 8.8.8.8: icmp_seq=5 ttl=112 time=8.76 ms
    

    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.


  2. 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.

    $subscription = "xxx"
    $resourceGroup = "Jahnavi"
    $vmname = "newvm"
    $sourceId = "/subscriptions/xxxx/resourcegroups/Jahnavi/providers/Microsoft.Compute/virtualMachines/newvm"
    $destinationId = "5 8.8.8.8"
    $desPort = "80"
    $requestBody = @"
    {
      'source': {
        'resourceId': '${sourceId}',
        'port': xx
      },
      'destination': {
        'address': '${destinationId}',
        'port': ${desPort}
      }
    }
    "@
    
    $response = armclient post "https://management.azure.com/subscriptions/{subscription}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{vmName}/runCommand?api-version=2023-07-01" $requestBody
    
    • Make sure the virtual machine has an outgoing Internet connection to reach the specified IP address. This may include checking NSG rules and ensuring that the virtual machine is properly configured for outbound Internet access.

    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.

    az vm run-command invoke -g Jahnavi -n newvm --command-id RunShellScript --scripts "ping -c 5 8.8.8.8"
    

    enter image description here

    You can also check activity logs under virtual machine resource for brief understanding on the error.

    enter image description here

    Login or Signup to reply.
  3. Here the output of "Activyty log". Activity log

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search