How to get VNC port number using libvirt?

can. picture can. · Nov 1, 2012 · Viewed 23.8k times · Source

I set autoport=yes in a domain's("virtual machine" in libvirt) config file so the VNC port is assigned automatically in the run time.

I need to get this port so I can connect to the vm from outside, but I can't find the proper API to do so. Better in python because I'm using the libvirt-python bindings.

Answer

liuzhijun picture liuzhijun · Nov 14, 2012

I have not found any API for the VNC port, not sure if the newer version of libvirt has this interface?

However, you can use the command virsh vncdisplay $domainName to show the port. NOTE: you must modify /etc/libvirt/qemu.conf enable vnc_listen='0.0.0.0'.