Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get VNC port number using libvirt?

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.

like image 462
can. Avatar asked Nov 01 '12 08:11

can.


People also ask

What is Virsh in Linux?

The virsh command allows you to manage VMs interactively or in batch. It's also helpful for controlling VMs from the Linux shell and integrates with scripts or automation tools.

What port does VNC use?

VNC by default uses TCP port 5900+N, where N is the display number (usually :0 for a physical display). Several implementations also start a basic HTTP server on port 5800+N to provide a VNC viewer as a Java applet, allowing easy connection through any Java-enabled web-browser.


1 Answers

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'.

like image 84
liuzhijun Avatar answered Sep 23 '22 02:09

liuzhijun