Search This Blog

Friday, February 5, 2010

androidVNC + DynDNS + X11vnc = accessing my laptop from my phone!

The goal: "to be able use my phone/PDA to access my Ubuntu laptop at home as if I was sitting at it."

OK, so over the past few posts I've covered things like Ubuntu, Android on my Motorola Milestone and a few other topics.  This post brings a few of these themes together into a very useful capability.

Have you ever been somewhere and thought "I've got that on my PC at home.  I wish there was someway I could get to it."  Well now you can.  The diagram below provides a graphical view of how the solution fits together.  I will cover the technical aspects in words and links.

The ingredients are:
  • Motorola Milestone (or any phone/PDA running Android)
  • androidVNC, a free application available in the Android Market
  • Ubuntu on your PC or laptop (most Linux distros supported)
  • X11vnc, free server software (author would like donations) for your home machine
  • DynDNA, a service that gives you a free URL to point to your home network
  • Port forwarding on your router
And this diagram provides a high-level view of the solution...


    Overcoming Challenges
    I tried several free apps from the Android Market and, whilst they all work, I found that I preferred androidVNC because it had a better selection of settings to alter its performance.

    On the Ubuntu side, I tried several of the VNC solutions like Vino, vnc4server, etc.  The problems I found with these solutions is that, although they displayed the initial screen on my laptop OK, they never refreshed it.  I eventually settled on X11vnc (created by Karl Runge) after wading through a lot of dismay from people, like myself, who are running Ubuntu 9.10 (Karmic Koala).

    How do I make my machine available from outside my home?
    I'm using the Broadband cable service from Optus (Optusnet).  It is connected to a D-Link DIR655 Router in my home.  The router provides both wired and unwired connectivity.

    Step 1: Port forwarding
    Port forwarding allows you to direct certain network traffic from/to a machine on your home network.  I'm not going to go into each detail here; suffice to say you need to forward ports 5500, 5800 & 5900 to your machine.  The Port Forward web site provides excellent advice for most routers.  You will also need to configure your router to set a fixed (internal) IP address for your machine.

    Step 2: Finding your network from the Internet
    Telco providers assign a single IP address to each of their customers.  Unless you have a business pack, the IP address is not fixed and it can change at any time; you will not know when or how often.  The solution?  DynDNS!  DynDNS provides free and paid DNS services.  The free service is more than enough for our needs.  Simply register at http://www.dyndns.org/ and select your URL from a large list.  The URL will point to the IP address of your home network.  But hang on!  That can be changed at any time by your telco.

    Correctomundo!  So that's why you install the free software from DynDNS that you can configure to run on your machine.  It checks to see whether the IP address of your network has been changed by your Telco.  If it has been changed, it tells DynDNS, who immediately point your URL to the new IP address - wonderful!  DynDNS provide 2 software clients, I used the "ddclient" option.  They provide online examples on the configuration file.  Start off using the basic example to get going.

    Let's see where we are so far.  You have a your own URL that will always point to your home network.  VNC traffic (that uses ports 5500, 5800 & 5900) will hit your router and be directed to your machine.  Now we need some software...

    Step 3: X11vnc Server

    NOTE THAT THIS SOLUTION IS FOR THE GNOME DISPLAY MANAGER (GDM).  YOU WILL NEED TO MODIFY IT FOR KDE

    For Ubuntu 9.10, you need to install version X11vnc-0.99.  Kamal Mostafa has done an excellent job of packaging this up for Ubuntu 9.10 hereSince we want the server to start automatically, then we need to do some work. Here are the instructions to achieve this (acknowledgement to ErikTheRed - original post here) - my comments are in RED:

     1. Install the package

    Code:
    sudo aptitude install x11vnc
     2. This step no longer required

     3. Add x11vnc service to xinetd

    Code:
    sudo nano /etc/xinetd.d/x11vnc
    Enter this into the new file:
    Code:
    service x11vnc
    {
            port            = 5900
            type            = UNLISTED
            socket_type     = stream
            protocol        = tcp
            wait            = no
            user            = root
            server          = /usr/bin/x11vnc
            server_args     = -inetd -o /var/log/x11vnc.log -display :0 -auth /var/lib/gdm/:0.Xauth -many -bg
            disable         = no
    }
    I have changed the value after -auth in the server_args parameter as with GDM it is a static file.

    4. Restart xinetd

    Code:
    sudo /etc/init.d/xinetd restart
    We now have X11vnc running on our Ubuntu machine and it can be accessed from the Internet.

    Step 4: androidVNC
    To download this app, simply open the Android Market app on your Android phone/PDA and install it.


    The cake is now baked - time to eat it.

    Fire up androidVNC and connect.  Here are some screen shots showing you some typical settings.


    Note: in the screenshots below, the shaded area followed by ":5900" is the URL you defined at DynDNS.




    Once you have connected to your machine, you have other androidVNC settings to play with.  I am not going to explain the whole application as it's pretty intuitive.

    I strongly advise you to leave your machine in Locked Screen - which means your password has to be provided in order to access Ubuntu.  If you want additional security you can configure X11vnc to prompt for a password or you can even use SSH to create a secure connection.  When you have finished, simply Lock Screen, then disconnect the androidVNC session by selecting Settings on androidVNC, click on More, then Disconnect.

    Enjoy!

    3 comments:

    1. UPDATE: I have removed the X11VNC server because I didn't need the extended capabilities. I just enabled the Ubuntu Remote Access service and it works fine from my Android...

      ReplyDelete
    2. Hi Pete,
      I would like to know since my operating system is Windows Vista do I have to switch to Ubuntu?
      I am a bit confused about step 3 where you install X11VNC and Ubuntu.
      I would appreciate it if you could guide me.
      Thanks

      ReplyDelete
    3. Reza

      You will still have to set up the access using dyndns. Windows vista should allow Rdp access. If you are using android, you can installa different app. It's called rdp lite. I have used it to connect from android to windows 2003 and it works fine.

      I hope this helps. Cheers Pete

      ReplyDelete