bash alias for a vmlookup
command (nslookup
but for Proxmox). Uses qm
and jq
.
put in .bashrc
:
function vmlookup () {
if [ "${1}" == "" ]; then echo -e "Get Proxmox VM ipv4 IP(s). \nUsage: vmlookup [vm name]" && return 1; fi
local vmid=$(qm list | egrep -i "\s${1}\s" | awk '{print $1}')
if [ "$vmid" == "" ]; then echo -e "[ERR] can't get VM ID" && return 1; fi
# exclude link local loopback, link local, docker standard subnet, carrier grade nat (tailscale, etc)
qm guest cmd $vmid network-get-interfaces | jq -r '.[] | .["ip-addresses"][] | select(.["ip-address-type"] == "ipv4" and (.["ip-address"] | tostring | test("^(127\\.0\\.0\\.1|169\\.254\\.|172\\.(1[6-9]|2[0-9]|3[0-1])\\.|100\\.(6[4-9]|[7-9][0-9]|1[01][0-9]|12[0-7])\\.)") | not)) | ."ip-address"'
return $?
$ vmlookup
Get Proxmox VM ipv4 IP(s).
Usage: vmlookup [vm name]
get VM IP from VM name:
vmlookup debian0026
10.172.1.20