Page 1 of 2

VNC instructions (Pi remote desktop)

Posted: Wed Apr 16, 2014 3:06 pm
by Davespice
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

Re: VNC instructions (Pi remote desktop)

Posted: Wed Apr 16, 2014 3:42 pm
by allenheard
Excellent, thanks for that! :)

Re: VNC instructions (Pi remote desktop)

Posted: Wed Apr 16, 2014 4:06 pm
by Theladdie
Ha perfect I was just about to google this but you beat me too it

Re: VNC instructions (Pi remote desktop)

Posted: Wed Apr 16, 2014 6:34 pm
by jamesrobinson
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.

Re: VNC instructions (Pi remote desktop)

Posted: Wed Jun 18, 2014 1:40 pm
by mrwalkerworld
Perfect!

Re: VNC instructions (Pi remote desktop)

Posted: Mon Jun 30, 2014 8:02 pm
by MrsKSayers
Exactly what I needed thank you

Re: VNC instructions (Pi remote desktop)

Posted: Mon Oct 06, 2014 7:10 pm
by guidolavespa
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.

Re: VNC instructions (Pi remote desktop)

Posted: Tue Oct 07, 2014 2:36 pm
by Carrie Anne
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.

Re: VNC instructions (Pi remote desktop)

Posted: Tue Oct 07, 2014 3:23 pm
by r3d4
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 ?)

Re: VNC instructions (Pi remote desktop)

Posted: Tue Oct 07, 2014 7:13 pm
by guidolavespa
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?

Re: VNC instructions (Pi remote desktop)

Posted: Tue Oct 07, 2014 7:14 pm
by DougieLawson
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.

Re: VNC instructions (Pi remote desktop)

Posted: Tue Oct 07, 2014 7:53 pm
by r3d4
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 .

Re: VNC instructions (Pi remote desktop)

Posted: Sun Nov 02, 2014 4:40 pm
by SuperWoman
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,

Re: VNC instructions (Pi remote desktop)

Posted: Sun Nov 02, 2014 4:46 pm
by DirkS
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.

Re: VNC instructions (Pi remote desktop)

Posted: Sun Nov 02, 2014 5:47 pm
by mikerr
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...

Re: VNC instructions (Pi remote desktop)

Posted: Sun Nov 02, 2014 6:19 pm
by DirkS
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.

Re: VNC instructions (Pi remote desktop)

Posted: Sun Nov 02, 2014 6:33 pm
by mikerr

Re: VNC instructions (Pi remote desktop)

Posted: Mon Nov 03, 2014 12:02 am
by SuperWoman
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.

Re: VNC instructions (Pi remote desktop)

Posted: Wed Nov 05, 2014 9:00 am
by richlane
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

Re: VNC instructions (Pi remote desktop)

Posted: Wed Nov 05, 2014 1:25 pm
by DirkS
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.

Re: VNC instructions (Pi remote desktop)

Posted: Tue Apr 07, 2015 8:09 pm
by asiainorama
WOW!!!!

Now I can use my Pi with my iMac and I no need more to connect to the TV.
My girlfriend will be really happy. ;)
The lag is minimum compared with wifi connection or ethernet through the router.
Congratulations!! It's a great tutorial, easy and clear.

Thanks a lot.

PS. It works faster with Real VNC Viewer than other solutions.

Re: VNC instructions (Pi remote desktop)

Posted: Thu Apr 09, 2015 7:11 pm
by asiainorama
Just 1 question.

Could be possible to connect internet through the same ethernet cable??

I've no idea if it's possible or not.

Re: VNC instructions (Pi remote desktop)

Posted: Mon May 11, 2015 5:47 pm
by feverish
I've only just seen this, for some reason Raspi has stopped emailing me whenever a 'watched' topic posts another message.
I was wanting to use something like this for my developing project, so extra thanks for the tutorial.

Re: VNC instructions (Pi remote desktop)

Posted: Mon Mar 07, 2016 9:17 am
by omenie
The new 'Minecraft over VNC' build is IMMENSE!

Re: VNC instructions (Pi remote desktop)

Posted: Fri Jan 13, 2017 10:52 pm
by RDS
I have reloaded NOOBS to get the version that includes VNC Server on the Pi and it is running OK.
I have loaded up VNC Viewer on a Windows 10 PC and entered the Pi IP address from my local network.

However, a window then comes and asks for a user name and password.

Could someone please advise where the user name and password come from.