VNC instructions (Pi remote desktop)

The Raspberry Pi Foundation's professional development course for teachers

20 posts
by Davespice » Wed Apr 16, 2014 3:06 pm
Image

Hi folks;
Allen was just asking me about the VNC demo I gave at Picademy and I thought I would just do a follow up post here for everyone.

  • Step 1: Setup and install
    So the aim will be to install the VNC server software on Pi and the VNC viewer software on the host computer (which will show the Pi desktop).
    Read and follow the guide here: https://github.com/raspberrypi/document ... access/vnc
    The guide includes instructions to make the VNC server start automatically when the Pi boots up (recommended).
  • Step 2: If necessary, configure the Pi to give out an IP address
    This is the method you'll want to use if you have untrusting network administrators who refuse to allow a Raspberry Pi to be connected to the main school network.
    I know this looks like loads to do but I've just put a lot of detail so you can't go wrong :)

    This way each Raspberry Pi will be directly connecting to a host computer using a single Ethernet cable, thus making a completely isolated point to point network between the two and therefore your network administrators shouldn't have any cause to complain. Note: you don't need a cross over cable for this, a standard cable will work because the Pi Ethernet port auto-switches the transmit and receive pins.

    Firstly we'll need to install some software on the Pi, so for this first part you'll need to connect it to a LAN for Internet access. We’re going to make the Pi Ethernet port behave in a similar way to a home router. This means assigning a static IP address to it and installing a DHCP service (dnsmasq) that will respond to address requests from the host computer.

    From the command line or LXTerminal enter these commands:

    Code: Select all
    sudo apt-get update
    sudo apt-get install dnsmasq

    It’s a good idea to use an IP address range that is very different to your main network, so let’s use 10.0.0.X. To configure this we must edit the network interfaces file, enter the following command;
    Code: Select all
    sudo nano /etc/network/interfaces

    Find the following line;
    Code: Select all
    iface eth0 inet dhcp

    Add a hash symbol at the start of the line to disable it and then add the other four lines shown below.
    Code: Select all
    # iface eth0 inet dhcp
    auto eth0
    iface eth0 inet static
    address 10.0.0.1
    netmask 255.255.255.0

    Press Ctrl – X, y and enter to save and quit out of nano. The Raspberry Pi will now have a static address of 10.0.0.1

    Next we need to configure dnsmasq (that we installed earlier) to give out IP addresses. I am going to explicitly specify a configuration file for the dnsmasq service so let’s first make a backup of the default config file and then save my one in its place.
    Code: Select all
    cd /etc
    sudo mv dnsmasq.conf dnsmasq.default
    sudo nano dnsmasq.conf

    You should now be editing a blank file. Copy and paste the following into it.
    Code: Select all
    interface=eth0
    dhcp-range=10.0.0.2,10.0.0.250,255.255.255.0,12h
    dhcp-option=3,10.0.0.1

    The first line tells dnsmasq to listen for DHCP requests on the Ethernet port of the Pi. The second line is specifying the range of IP addresses that can be given out. The third line provides the default gateway for the host computer (which won't actually be used here).

    Next disconnect the Pi from the LAN and reboot.
    Code: Select all
    sudo reboot

    After the Pi boots back up, give it a minute or so, and you can go ahead and plug in the single Ethernet cable directly from the Pi to the host computer.
    The host computer should then be given an IP address which will be 10.0.0.X where X is a random number between 2 and 250.

    One thing to try is to open up a command prompt on the host computer (a Terminal on OSX and Linux) and enter the following command;
    Code: Select all
    ping 10.0.0.1

    If you see reply, reply, reply then it's working. If you see request timed out then something is wrong and you'll need to go back and double check everything.
    You can now open up your VNC viewer on the host PC and connect it to the Pi. When prompted for the remote host enter: 10.0.0.1:1 and click connect. It could also be 10.0.0.1:0 depending on how you set it up in step 1.

    You'll be prompted for the password that you chose during step 1 and after that you'll see the Pi desktop and will be able to get going with Scratch or whatever. Remember that 3D games like Minecraft are not going to work using this method, those draw their image directly to the local screen memory and will be ignored by VNC. You'll just see an empty window.

I hope this helps, please point out any errors if you spot them. One thing to note is that this setup will not have internet access, since you're supposed to be on an isolated point to point network to keep the network administrators happy. If you want to reverse this setup and make the Pi go back to normal (so you can get online) you'll need to do three things:

  • Undo the change to /etc/network/interfaces (put hashes on the four lines you added and remove the hash from the original line).
  • Run sudo apt-get remove dnsmasq from the command line.
  • sudo reboot
User avatar
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 1458
Joined: Fri Oct 14, 2011 8:06 pm
Location: London, United Kingdom
by allenheard » Wed Apr 16, 2014 3:42 pm
Excellent, thanks for that! :)
User avatar
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 4
Joined: Tue Apr 15, 2014 1:45 pm
by Theladdie » Wed Apr 16, 2014 4:06 pm
Ha perfect I was just about to google this but you beat me too it
User avatar
Posts: 23
Joined: Mon May 14, 2012 11:38 am
Location: Berlin, Germany
by mrmandrill » Wed Apr 16, 2014 6:34 pm
Davespice, that's great. Using similar technique in school myself, we've switched on the Internet connection sharing option in windows PCs and left the Pi on dynamic IP. The Pi belong to our pupils so they go home each evening and static IP wouldn't always work on their home network.

We then use a combination of Avahi on the Pi to broadcast it's IP and Bonjour on the PC, this means the Pi can be addressed by name and consistently accessed with ease.
User avatar
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 30
Joined: Fri Jul 20, 2012 9:12 am
Location: Cambridge
by mrwalkerworld » Wed Jun 18, 2014 1:40 pm
Perfect!
Posts: 3
Joined: Wed Jun 18, 2014 12:55 pm
Location: Bury, UK
by MrsKSayers » Mon Jun 30, 2014 8:02 pm
Exactly what I needed thank you
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 16
Joined: Wed Jun 11, 2014 11:53 am
Location: Derby
by guidolavespa » Mon Oct 06, 2014 7:10 pm
Sorry, stupide question. But I wanted to print these instructions, but there are always some line(s) missing...How it could be done best?
PS for Firefox.
Posts: 4
Joined: Fri Oct 11, 2013 7:30 pm
by Carrie Anne » Tue Oct 07, 2014 2:36 pm
This guide has been added to the foundation website resource section: http://www.raspberrypi.org/learning/tea ... m-guide.md

You should be able to print it from there.
User avatar
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 58
Joined: Sat Sep 29, 2012 4:11 pm
Location: London
by r3d4 » Tue Oct 07, 2014 3:23 pm
Carrie Anne wrote:This guide has been added to the foundation website resource section: http://www.raspberrypi.org/learning/tea ... m-guide.md

You should be able to print it from there.


Unfortunately minus the diagram !
Any reason that it had to been omitted ? ( perhaps to save ink ?)
Real life is, to most , a long second-best, a perpetual compromise between the ideal and the possible.
what about spike milligan??
Posts: 279
Joined: Sat Jul 30, 2011 8:21 am
Location: ./
by guidolavespa » Tue Oct 07, 2014 7:13 pm
This forum is made in PhPBB, so there is the posibilitie to add the print icon so that posts can be printed!
Can this be doen?
Posts: 4
Joined: Fri Oct 11, 2013 7:30 pm
by DougieLawson » Tue Oct 07, 2014 7:14 pm
guidolavespa wrote:This forum is made in PhPBB, so there is the posibilitie to add the print icon so that posts can be printed!
Can this be doen?


Why do you need that?
CTRL+P works in my browser.
Hacker on ZX80, Microtan65, Raspberry Pis and Arduinos
Unemployed mainframe database troubleshooter
RPi owner since 2012.
Twitter: @DougieLawson


Please post technical questions on the forum, not by personal message. Thanks!
User avatar
Posts: 8522
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
by r3d4 » Tue Oct 07, 2014 7:53 pm
guidolavespa wrote:This forum is made in PhPBB, so there is the posibilitie to add the print icon so that posts can be printed!
Can this be doen?


I-cant be doen it , for shore .
Real life is, to most , a long second-best, a perpetual compromise between the ideal and the possible.
what about spike milligan??
Posts: 279
Joined: Sat Jul 30, 2011 8:21 am
Location: ./
by SuperWoman » Sun Nov 02, 2014 4:40 pm
Hi David!

My B+ is updated to the latest (apt-get update and apt-get upgrade).

It works. I can connect to the VNC from my Yosemite Mac.

But.... BUT..... if the pi reboots the VNC server doesn't start automatically...

How do I get it to start automatically?

thanks,
User avatar
Posts: 11
Joined: Tue Oct 07, 2014 1:04 am
by DirkS » Sun Nov 02, 2014 4:46 pm
SuperWoman wrote:How do I get it to start automatically?

See section 'automation and run at boot' in http://www.raspberrypi.org/documentatio ... /README.md

HTH
Dirk.
Posts: 2005
Joined: Tue Jun 19, 2012 9:46 pm
Location: Staffordshire, UK
by mikerr » Sun Nov 02, 2014 5:47 pm
Somewhat simpler :

Code: Select all
sudo apt-get install xrdp

That sets it up to run on boot as well.

Then use windows remote desktop to connect to it...
Got a Pi Camera? View it in my android app - Raspicam Remote ! No software required on the pi
User avatar
Posts: 1327
Joined: Thu Jan 12, 2012 12:46 pm
Location: NorthWest, UK
by DirkS » Sun Nov 02, 2014 6:19 pm
Then use windows remote desktop to connect to it...

Is that available for the Mac?
SuperWoman wrote:It works. I can connect to the VNC from my Yosemite Mac.
Posts: 2005
Joined: Tue Jun 19, 2012 9:46 pm
Location: Staffordshire, UK
by mikerr » Sun Nov 02, 2014 6:33 pm
Got a Pi Camera? View it in my android app - Raspicam Remote ! No software required on the pi
User avatar
Posts: 1327
Joined: Thu Jan 12, 2012 12:46 pm
Location: NorthWest, UK
by SuperWoman » Mon Nov 03, 2014 12:02 am
DirkS wrote:
Then use windows remote desktop to connect to it...

Is that available for the Mac?
SuperWoman wrote:It works. I can connect to the VNC from my Yosemite Mac.



Well, to be precise, a Windows 7 VM running in Parallels will connect.
When I try to start the vncserver it tells me its already running on #1, but I can connect unless I try to manually start it.
User avatar
Posts: 11
Joined: Tue Oct 07, 2014 1:04 am
by richlane » Wed Nov 05, 2014 9:00 am
I followed the instructions mention earlier in the post to start the VNC server at boot which saves a few seconds each time you reboot the pi having to ssh in to start it.

> See section 'automation and run at boot' in http://www.raspberrypi.org/documentatio ... /README.md

which works great, thanks. I also modified the vncserver command in the script run at boot time to run the server as user 'pi' rather than 'root' which is what it was doing. My question is whether this is good practice on Linux systems?

sudo -u pi /usr/bin/vncserver :0 -geometry 1280x800 -depth 16 -pixelformat rgb565
Posts: 4
Joined: Thu Mar 13, 2014 9:37 pm
by DirkS » Wed Nov 05, 2014 1:25 pm
richlane wrote:I also modified the vncserver command in the script run at boot time to run the server as user 'pi' rather than 'root' which is what it was doing. My question is whether this is good practice on Linux systems?

Did you use the 'init.d' script? IIRC you just have to set USER and HOME to the correct values to have it run as pi:
Code: Select all
USER=pi
HOME=/home/pi


Gr.
Dirk.
Posts: 2005
Joined: Tue Jun 19, 2012 9:46 pm
Location: Staffordshire, UK