azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

The command to get just an IP address of a VM is too complicated

Open svick opened this issue 9 years ago • 6 comments

I'm playing with the new CLI and wanted to figure out what is the right command to get the public IP address of one of my VMs, so that I can connect to it from bash using ssh `az whatever`.

As far as I can tell, the command to do that is:

ssh `az vm list-ip-addresses -n vm-name --query [0].virtualMachine.network.publicIpAddresses[0].ipAddress -o tsv`

Is there a simpler way to do this? If not, I think that's way too complicated for something like this.

svick avatar Mar 30 '17 09:03 svick

@svick, you can use 'az vm show -d'

yugangw-msft avatar Mar 30 '17 17:03 yugangw-msft

More specifically I've had success with '(az vm show --name | ConvertFrom-Json).publicIps'

paulpal1 avatar Aug 03 '18 18:08 paulpal1

Getting below error when querying for ip address of the server (az vm show --name server01 | ConvertFrom-Json).publicIps -bash: syntax error near unexpected token `.publicIps'

kgopi05 avatar Oct 01 '18 11:10 kgopi05

For vms => az vm list-ip-addresses --output table For vm by name => az vm list-ip-addresses --output table -n

To view in JSON format remove ' --output table' from the above commands.

benktesh avatar May 29 '19 23:05 benktesh

get only local vm ip address https://rapidsol.blogspot.com/2019/11/command-for-vm-ip-address-only.html

ifconfig eth0 or ifconfig ens33

You have to type above of interface name to get single ip address.

flik avatar Nov 10 '19 06:11 flik

az vm show -d --name myVM --resource-group myRG --query publicIps

elliott-fwdsec avatar Apr 14 '21 17:04 elliott-fwdsec