I have a script to make temp VMs
I don’t know if it’s covered in here. But with the 2 VLANS I can’t remote into them by name, I put Temp101, Temp102 etc in my hosts file, but I need to know what their IP is.
Script to get the IP of a VM
#!/bin/bash
read -p "Which VM? " VM
IP=$(qm guest exec "$VM" -- ipconfig | grep -oP 'IPv4 Address[. ]*: \K[0-9.]+' | grep -v '^169\.254\.' | head -n1)
if [ -n "$IP" ]; then
echo "VM $VM is on $IP"
else
echo "Couldn't get an IP for VM $VM (is it running, with the guest agent installed?)"
fiRelated: Proxmox Terminal Commands (the other qm one-liners), Tailscale auto-enroll for temp VMs (same qm guest exec + qemu-guest-agent pattern against the Windows template), my disposable windows
Followup
- Windows guests only: it runs
ipconfiginside the guest. A Linux VM would needip -4 addrinstead, or skip the exec entirely withqm guest cmd <vmid> network-get-interfaces, which works for any guest with the agent running. qm guest execreturns JSON with the output inout-data(escaped\r\n), so the grep is matching inside that JSON blob. Works, just worth knowing if it ever stops matching.- Could be a one-liner section in Proxmox Terminal Commands rather than its own page. Left separate with
publish: falseso nothing new goes live on howto.coytis.me without you looking.