VNC allows remote access to the desktop. The following installation requires opening a port in you router for port forwarding to the Raspberry Pi. VNC is not a safe application, it can be exploited. Your Internet Service Provider (ISP) may not like it. They log hack attempts on your router/modem.
2.0 We must change the Pi password from the default. By default the username is pi and the password is raspberry. Use a strong password or passphrase. Type in passwd into the command line. You will be prompted for the current password (raspberry). Enter it. You will then be prompted twice for a new password. It will end with the message (passwd: password updated successfully).
2.1 RealVNC allows access to the Pi desktop from Windows, Linux, and your Android phone. First we will discuss the Raspberry Pi setup, then the Windows client setup, then the DDNS setup, and finally the Port Forwarding on your router.
2.1.1 First update your repository
sudo apt-get update
2.1.2 Install RealVNC server
sudo apt-get install realvnc-vnc-server
2.1.3 Enable VNC Server in the Pi configuration file with following steps:
sudo raspi-config
Navigate to Interfacing options
Select VNC
Answer Yes
Tab to Finish
2.1.4 Download RealVNC client to your Windows computer from https://www.realvnc.com/fr/connect/download/viewer/windows .
2.1.5 If the Windows computer and the Pi computer are on the same network (use the same router/modem) test the connection with RealVNC and the local network IP address for the Raspberry Pi computer. To find the IP address for Pi, type the following at the Pi command prompt:
hostname -I
2.1.6 Go back to the Windows computer, open the RealVNC client and type in the IP address for the Pi computer. You will be prompted for the Pi username and password. After entering them you should have a connection to the Pi desktop. If there is no connection setup DDNS and port forwarding.
2.1.7 If you completed Chapter 1, you already have DDNS setup on the Raspberry Pi. You can add Port Forwarding on the router to the Raspberry Pi computer. Add Port 5900 with TCP protocol. Port 5900 is the port we need open for RealVNC.
2.2.1 Here is repeat of Chapter 1 instructions.
2.3.1 We need DDNS to access the Raspberry Pi from outside your network. Sign up for a free DDNS domain name and authentication token at www.duckdns.org . It is very simple to sign up for. I used my google email account. You will be provided an authentication token, and you will select a domain name. You need your sign in password to access the authentication token. You can access either the sign in page or install directions page separately, but not both at the same time. To simplify things, the instructions are given below.
2.3.2 On your Pi, change to your home directory, create a duckdns directory, change to the duckdns directory, and open a file with Nano text editor called duck.sh.
cd ~
mkdir duckdns
cd duckdns
nano duck.sh
2.3.3 Copy and paste the following into duck.sh .
echo url="https://www.duckdns.org/update?domains=exampledomain&token=a7c4d0ad-114e-40ef-ba1d-d217904a50f2&ip=" | curl -k -o ~/duckdns/duck.log -K -
2.3.4 Use the cursor and backspace keys to delete the exampledomain and the token in duck.sh . Replace them with yourdomain.duckdns.org domain and the token from www.duckdns.org . You can copy and paste the token. In Nano text editor press Ctrl + x, press y, and press Enter. Your changes to duck.sh are now saved and the file closed.
2.3.5 Make the duck.sh file executable.
chmod 700 duck.sh
2.3.6 Next we will be using the cron process to make the script run every 5 minutes. Enter the following command and select the Nano editor to open crontab.
crontab -e
2.3.7 Move the cursor to the bottom of crontab, and copy and paste the following.
*/5 * * * * ~/duckdns/duck.sh >/dev/null 2>&1
Press Ctrl + x, press y, and press Enter.
2.3.8 Test the script. The output should return you to the prompt.
./duck.sh
2.3.9 We will check to see if the script was successful. If it is Ok it will say Ok. If there is a problem it will say KO. If it says KO then double check your Token and Domain in the duck.sh script.
2.3.10 Restart your Pi
sudo reboot now
2.4.1 You must activate port forwarding on your router. I am using a standard Cox Panoramic Router/Modem. Log into your router. Locate Port Forwarding. Then select the Pi computer on my network. Under Port, I typed 5900. Under Protocol, I selected TCP. Actually it took a little effort to find Port Forwarding. I used the following steps on my Cox Panoramic Router/Modem.
Log in to router.
Advanced Settings
Port Forwarding (There is a link to the Cox website.)
Connect tab
See Network
Advanced Settings
Port Forwarding
Add Port Forward
Select the raspberrypi computer
Select Protocol (TCP)
Type in the Port Number (5900)
2.4.2 Test the RealVNC connection again using the DDNS domain name. It should work.
Table of Contents
Ch1-SSH
Ch2-VNC
Ch3-Motion Camera
Ch4-Remote Viewing