KVM - The Linux Kernel-Based Virtual Machine
News, Blogs and Resources on the Linux (KVM) Kernel-Based Virtual Machine

Two ways to access your virtual machine monitor across the network

Running your KVM virtual machines headless in a data center environment using the built in vnc server is a neat feature of KVM but what happens when you want to access your monitor from across the network? Well, it turns out there’s an option for redirecting your monitor to tcp sockets and there are two methods of doing this.

 

 

The tcp options

There are two basic options for redirecting your monitor to tcp sockets, namely raw socket and using the telnet protocol. I’ll go ahead and show the syntax for both options then discuss the options you have. For redirecting your monitor to raw tcp socket you use the following syntax:

-monitor tcp:192.168.1.1:4444,server,nowait 

For redirecting to a socket supporting telnet protocol you use the following syntax

-monitor telnet:192.168.1.1:4444,server,nowait

 

The options are

  • tcp – raw tcp sockets
  • telnet – the telnet protocol is used instead of raw tcp sockets. This is the preferred option over tcp as you can break out of the monitor using Ctrl-] then typing quit. You can’t break out of the monitor like this after connecting with the raw socket option
  • 192.168.1.1 – Listen on this port only. You can use 127.0.0.1 if you want to only allow connections locally. If you want to listen on any ip address on the server, just leave this blank so you end up with two consecutive colons ie “::” .
  • 4444 – port number to listen on.
  • server – listening in server mode
  • nowait – qemu will wait for a client socket application to connect to the port before continuing unless this option is used. In most cases you’ll want to use the nowait option.

 

An example

So as an example for your typical case where you have your headless kvm virtual machine running with a vnc server and want to access the monitor from across the network, you’d probably want to use the following command to start your virtual machine.


qemu-system-x86_64 –m 400 –hda windows.img –usbdevice tablet –vnc :1 –monitor  telnet:192.168.1.100:4444,server,nowait 

If you’re going to be listening on any ip addresses on your server, you can also use

qemu-system-x86_64 –m 400 –hda windows.img –usbdevice tablet –vnc :1 –monitor  telnet::4444,server,nowait 

Now in order to access your virtual machine monitor from across the network you would type the following

telnet 192.168.1.100 4444

This would give you access to your monitor remotely. To close and break out of the monitor you simply type Ctrl-] to get the telnet prompt then type quit. If you don't type the Ctrl-] followed by quit and only type the quit command, you'll kill your virtual machine ungracefully. If you have security on your virtual machine host server such as ssh, then you can either ssh to the host server then telnet to localhost or use ssh tunneling.

So next time you’re thinking about running headless kvm machines and wondering how to manage them remotely you have two more options. 

See Also

Comments

Hi Haydn, Thanks for the

Hi

 

 

Re: Thanks.. monitor

Hi J,

Glad that the information was useful to you.. maybe you'll make the switch to KVM. :)  So I did some initial investigations and libvirt already has an interface for the monitor but when looking at virtinst I don't see any use of it however I didn't look in detail. I do agree that this is an important feature as no sense in remote control if you have no access to monitor. I will spend more time later looking through the various tools to see if there's an feature that makes use of the libvirt monitor interface.

I will continue to post information on features of KVM as I discover them as it's not well documented and information is difficult to find. Regardless of this fact, I think KVM is a really good piece of software and will be around for a long time.

Thank You!!

I have been wondering if this was possible and couldn't figure out what to search for to find how to do it! Thank you!

ssh-tunneling to provide vnc

You don't need to use these socketmajigs, you can use vnc over ssh-tunneling to get into the virtual machine.

Re: ssh-tunneling to provide vnc

It's not the same thing. The article is referring to the qemu monitor interface.. NOT the virtual machine graphical console.

libvirt & monitor usage

Hello Hadyn,

did you succeed with your investigation how libvirt should be configured to make use of the monitor feature you described above?

I didn't succed with my own search. Perhaps you know where to search?

Thanks.

NicoP.

Qemu with Window Host

i am running Qemu on windows-xp (host) and guest is Linux. I want to give command to qemu through host machine command. Is this useful in that case?

I tried but no success.

Re: qemu with window host

Assuming that you're running the version from qemu.org; no, this command will not work on a windows host. The version running on windows is very outdated.

Post new comment

The content of this field is kept private and will not be shown publicly.