How to find a VM or container by IP address in Proxmox VE

This article explains how to locate a virtual machine or container in a Proxmox VE cluster using its IP address.

Prerequisites

  • SSH access to the Proxmox node with root privileges
  • QEMU Guest Agent installed and running on VMs (for QEMU virtual machines)
  • The jq utility available on the system

Script

#!/bin/bash
TARGET_IP="192.0.2.100"

pvesh get /cluster/resources --type vm --output-format json | \
  jq -r '.[] | select(.status=="running") | "\(.type) \(.node) \(.vmid) \(.name)"' | \
  xargs -P 10 -L 1 bash -c '
    type=$1; node=$2; vmid=$3; name=$4
    if [ "$type" = "qemu" ]; then
      result=$(timeout 3 pvesh get /nodes/$node/qemu/$vmid/agent/network-get-interfaces --output-format json 2>/dev/null)
      if echo "$result" | jq -e ".result[].\"ip-addresses\"[]? | select(.\"ip-address\" == \"'"$TARGET_IP"'\")" > /dev/null 2>&1; then
        echo "Found: VMID $vmid ($name) on node $node [QEMU]"
      fi
    elif [ "$type" = "lxc" ]; then
      result=$(timeout 3 pvesh get /nodes/$node/lxc/$vmid/interfaces --output-format json 2>/dev/null)
      if echo "$result" | jq -e ".[] | select(.inet == \"'"$TARGET_IP"'\" or (.inet | startswith(\"'"$TARGET_IP"'/\")))" > /dev/null 2>&1; then
        echo "Found: VMID $vmid ($name) on node $node [LXC]"
      fi
    fi
  ' _

Replace 192.0.2.100 with the IP address you want to search for.

How It Works

  1. Gets the resource list: Queries the Proxmox API to get all VM-type resources in the cluster.
  2. Filters by type: Separates QEMU virtual machines from LXC containers.
  3. Parallel queries: Runs up to 10 simultaneous queries to speed up the search.
  4. Queries interfaces:
    • For QEMU: Uses the Guest Agent endpoint (/agent/network-get-interfaces).
    • For LXC: Uses the interfaces endpoint (/interfaces).
  5. Displays result: If the IP is found, displays the VMID, name, node, and type (QEMU or LXC).

Example Output

Found: VMID 105 (web-server) on node pve1 [QEMU]
Found: VMID 200 (dns-server) on node pve2 [LXC]

Notes

  • For QEMU VMs, the script requires the QEMU Guest Agent to be installed and running.
  • For LXC containers, no additional agent is required.
  • The 3-second timeout prevents VMs without Guest Agent or with communication issues from blocking the search.