Bash Script - Creating a Proxmox VM IP List
I needed a basic overview of all my virtual machines on Proxmox, with a few details about each one. The pvesh get /cluster/resources --type vm
command gives us a pretty decent amount of information about the VMs, but it doesn’t include the current IP addresses. So, I wrote this little bash script to get that info.
This script generates a list of all VMs in a Proxmox cluster, listing each VM’s ID, name, status, and IP addresses (if available). For running VMs, it attempts to retrieve the IP address using the QEMU guest agent. If no IP is available, it shows a clear message. Stopped VMs are also listed, marked as “VM is powered off” for clarity.
You’ll find the full script on my GitLab script-collection repository.
Features
- Lists all VMs, whether running or stopped.
- Shows IP addresses for running VMs with a working QEMU guest agent.
- Displays a clear message when the IP is unavailable.
- Clean, readable output in a single line per VM.
Notes
- The QEMU guest agent must be installed inside each VM to retrieve IP addresses.
- IP addresses are comma-separated if multiple IPs are found for a VM.
Requirements
- Proxmox VE with access to the
qm
command. Tested with PVE 8.2.4. - QEMU Guest Agent installed and running on VMs to retrieve IP addresses.
Usage on a PVE Node
- Make the script executable
chmod +x get-pve-vm-ip-list.bash
- Run the script
./get-pve-vm-ip-list.bash
Example Output
ID - Name - Status - IP Address
101 - WebServer - running - 192.168.1.101, 10.0.0.5
102 - DBServer - stopped - VM is powered off
103 - AppServer - running - No IP (QEMU guest agent not available)
104 - Backup - running - 192.168.1.104
Some Explanations in Detail
Loop
for vmid in $(qm list | awk 'NR>1 {print $1}'); do
- This line initiates a for loop to iterate over each VM ID in the Proxmox environment.
$(...)
: This syntax captures the output of a command, so it can be used as a list of values to iterate over in the loop.qm list
: This command lists all VMs managed by Proxmox, showing their VM ID, name, and status.awk 'NR>1 {print $1}'
: Filters out the header line (NR>1
skips the first line) and extracts only the first column (print $1
), which contains the VM IDs.
Get VM Names
name=$(qm config $vmid | grep '^name:' | awk '{print $2}')
- Retrieves the name of the VM specified by
$vmid
. - Runs
qm config
for the current VM ID ($vmid
), which outputs the VM’s configuration details, including the VM name. grep '^name:
’: Filters the configuration output to lines starting withname:
, which contains the VM’s name.awk '{print $2}'
: Extracts the second field, which is the actual name of the VM.
Get IP Addresses
ip_addresses=$(qm guest exec $vmid -- ip -4 -br addr show 2>/dev/null
| grep -oP '\d+\.\d+\.\d+\.\d+' | grep -v '^127\.' | paste -sd ", ")
- Tries to retrieve all non-localhost IP addresses of the VM (if available), separated by commas.
qm guest exec $vmid -- ip -4 -br addr show
: Executesip -4 -br addr show
inside the VM usingqm guest exec
. This command requires the QEMU guest agent to be running inside the VM. It lists the IPv4 addresses of all network interfaces in a brief format.2>/dev/null
: Suppresses any errors, so if the guest agent isn’t available, there won’t be an error message.grep -oP '\d+\.\d+\.\d+\.\d+'
: Extracts only the IP addresses from the output by matching any patterns that resemble IPv4 addresses.grep -v '^127\.'
: Excludes 127.0.0.1, the loopback address, from the IP list.paste -sd ", "
: Joins the remaining IP addresses into a single line, separated by commas.
Check IP Addresses
if [ -z "$ip_addresses" ]; then
- Checks if the
ip_addresses
variable is empty (meaning no IPs were found). -z "$ip_addresses"
: The-z
option tests if the given string is empty.- This condition will be
true
ifip_addresses
is an empty string, meaning the VM either doesn’t have an IP or the guest agent didn’t provide one.