Jul 192010

AndroidVNC is an Android app that can be used to connnect and control a remote machine which runs a VNC server. There are many VNC servers available like RealVNC, TightVNC, X11VNC server etc. The VNC server listens to a port (typically 5900) which the VNC client, can connect to and view/control the machine remotely.

Running it on a machine is quite straightforward. All you need to do is to start the TightVNC service and connect it from the phone using the app that can be downloaded from the market. It works great and can be used to control your PC from anywhere as long as its connected to the net.

But when you want to connect to a machine running on a VM, things can get a bit tricky. Mainly because of the way VirtualBox works. The default networking mode between a Host OS and the guest OS is NAT (Network Address Translation), which makes the VirtualBox as an intermediary between the Host and the guest and maps traffic to and fro. Though this mode requires virtually no configuration, it also makes the guest OS inaccessible from the outside world. Since any VNC viewer requires connectivity to the VNC server running on a machine, this limitation was effectively a dealbreaker.

To avoid this, the packets which reach the host must be sent to the guest through some mechanism. VirtualBox provides such a mechanism to do it and the protocol is called SSH (Secure Shell) which allows two networked devices to exchange data with each other. What happens is we open a port on the host side and forward any data received to a specified port on the guest through TCP. However, the GUI interface doesn’t give this option, its in a command line tool called VBoxManage. Before running this command, get the local IP address from Ubuntu using the ifconfig command. The IP was

Now we need to tell VirtualBox to forward all data received on any specified host port to port 5901 on Ubuntu.
I used the port 2222. The command for this is given below. Keep in mind that the VM needs to be powered off to use this command. Here you need to substitute your VM name with VM_NAME_here parameter. The guestssh is just a name assigned to it and doesnt really matter. Next comes the protocol – TCP, followed by the port on the host 2222. The two values after it signify the local IP for the guest OS and and port on the guestOS which will recieve the data.

VBoxManage modifyvm "VM_name_here" --natpf1 "guestssh,tcp,,2222,,5901"

Now that forwarding is configured, power on the VM again and install any VNC server on Ubuntu. I used X11VNC for this exercise.

sudo apt-get install x11vnc vnc-java

After X11VNC is installed, start it by going to Applications -> Internet -> X11 VNC server. It will display a dialog asking for the options. Make sure the port is 5901 and click on OK.

After clicking on OK, in the next screen. Make sure the Accept Connections tab is checked and also give a password and click on Ok. The X11VNC should be visible on the top left of the screen (If you are using GNOME)

Now that VNC is listening to port 5901 on the server, you can test it by running a VNC viewer on the localhost and specifying the port 2222 and seeing if the connection is made. The host would be This connection should be forwarded to the Ubuntu’s 5901 and the connection should succeed. If not see the logfile of the X11VNC to see if the connection was rejected due to some reason.

If your all set, run the AndroidVNC application on your phone. Also a very important point – “If you are accessing the net through a slow connection such as GPRS, make sure the resolution on Ubuntu is set to the miminum to prevent timeouts.” Get the network IP of your host through ipconfig or a site such as whatsmyip.com and enter the required settings on your phone.

Nickname: Any nickname you want
Password : What you specificied on X11VNC
Address: The public IP of your computer you got from ipconfig.
Port: 2222

And hit connect. It might take upto a minute to draw the first frame. Once thats done, you will be able to completely control the computer from your phone.

You can also send text and other key commands to the VM from your phone using the app options. Just How cool is that??