Monday, December 5, 2016

Remote Access Raspberry Pi from Anywhere and Dynamic DNS Update with Dynu.com

After installed Raspberry Pi in your environment with Internet connection with my previous post, next step for Pi lover is how to configure your Pi so you can control it from anywhere you go. 
From the research by Google, I found there are two websites providing free service to remote access your Pi from anywhere through Internet.


1. Weaved Remot3.it

Note: Weaved has evolved to become remot3.it. Once Remot3.it process verfifed, I will update this part again. 


1.1 Upgrade a Pi to remot3.it over a Weaved SSH connection

Use these instructions ONLY if you are connecting to the Pi over a Weaved ssh connection. 

Add your Pi and all your Weaved services to remot3.it today



1.2 Upgrade your Pi to remot3.it from Weaved
Use these instructions ONLY when you have physical access to the Pi via a LAN connection (Wi-Fi or ethernet). Or use a USB (or bluetooth) keyboard+mouse and HDMI monitor.

Step 1 of 4
Open up a command line on your Pi using either a keyboard+HDMI monitor or an ssh connection over a Wi-Fi or ethernet LAN.
Step 2 of 4
Update the package list on your Pi so you will get the latest version of the weavedconnectd package
>  sudo apt-get update
Step 3 of 4
Download and install the weavedconnectd deb package that includes support for remot3.it by entering the following command.
>  sudo apt-get install weavedconnectd
Step 4 of 4
Run weavedinstaller from the command line.
sudo weavedinstaller
Use the on-screen Sign In Menu (shown below) to Sign In to your remot3.it account by entering "1" at the prompt. Use your pre-existing Weaved account email and password to Sign In to www.remot3.it88.

Next, when prompted to enter a device name, give your Pi a device name (ex. my_Pi_001 ) as shown below. The device name entered will be displayed in the remot3.it portal. You can edit the device name later at any time. Type in a name and press Enter, then let the installer finish and return to the prompt. Then Exit the interactive menu installer by entering "4". (menu item 4).



login as: pi
[email protected]'s password:
Linux raspberrypi 4.1.7-v7+ #817 SMP PREEMPT Sat Sep 19 15:32:00 BST 2015 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Mon Dec  5 10:49:33 2016 from 19.26.16.129
[email protected] ~ $
[email protected] ~ $ sudo apt-get update
Get:1 http://archive.raspberrypi.org wheezy Release.gpg [473 B]
Hit http://raspberrypi.collabora.com wheezy Release.gpg
Get:2 http://mirrordirector.raspbian.org wheezy Release.gpg [473 B]
Hit http://raspberrypi.collabora.com wheezy Release
Get:3 http://mirrordirector.raspbian.org wheezy Release [14.4 kB]
Get:4 http://archive.raspberrypi.org wheezy Release [17.6 kB]
Hit http://raspberrypi.collabora.com wheezy/rpi armhf Packages
Get:5 http://mirrordirector.raspbian.org wheezy/main armhf Packages [6,935 kB]
Get:6 http://archive.raspberrypi.org wheezy/main armhf Packages [145 kB]
Ign http://raspberrypi.collabora.com wheezy/rpi Translation-en_GB
Ign http://raspberrypi.collabora.com wheezy/rpi Translation-en
Ign http://archive.raspberrypi.org wheezy/main Translation-en_GB
Ign http://archive.raspberrypi.org wheezy/main Translation-en
Get:7 http://mirrordirector.raspbian.org wheezy/contrib armhf Packages [23.6 kB]
Get:8 http://mirrordirector.raspbian.org wheezy/non-free armhf Packages [49.3 kB                                                                             ]
Get:9 http://mirrordirector.raspbian.org wheezy/rpi armhf Packages [592 B]
Ign http://mirrordirector.raspbian.org wheezy/contrib Translation-en_GB
Ign http://mirrordirector.raspbian.org wheezy/contrib Translation-en
Ign http://mirrordirector.raspbian.org wheezy/main Translation-en_GB
Ign http://mirrordirector.raspbian.org wheezy/main Translation-en
Ign http://mirrordirector.raspbian.org wheezy/non-free Translation-en_GB
Ign http://mirrordirector.raspbian.org wheezy/non-free Translation-en
Ign http://mirrordirector.raspbian.org wheezy/rpi Translation-en_GB
Ign http://mirrordirector.raspbian.org wheezy/rpi Translation-en
Fetched 7,186 kB in 22s (320 kB/s)
Reading package lists... Done
[email protected] ~ $ sudo apt-get install weavedconnectd
Reading package lists... Done
Building dependency tree
Reading state information... Done
weavedconnectd is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 144 not upgraded.
[email protected] ~ $ sudo weavedinstaller
Weaved connection installer Version: v1.3-02_Pi

Checking your network for compatibility...

Your network is compatible with Weaved services.
Please enter your Weaved Username (email address):
[email protected]

Please enter your password:
You have entered either an incorrect username or password. Please try again.
Press the 'Enter' key to continue.
Please enter your Weaved Username (email address):
[email protected]

Please enter your password:
=========================================================
Protocol        Port    Service         Weaved Name
=========================================================
TCP             3389    xrdp            xrdp-pi
SSH             22      sshd            jrasp-ssh


********************** Main Menu ************************
*                                                       *
*       1) Attach/reinstall Weaved to a Service         *
*       2) Remove Weaved attachment from a Service      *
*       3) Exit                                         *
*                                                       *
*********************************************************

Please select from the above options (1-3):
3
[email protected] ~ $









Weaved provides your Raspberry any TCP based service you want to make available remotely – securely and without port forwarding
• SSH on port 22
• Web (http) on port 80
• WebIOPI on port 8000 (Raspberry Pi only)
• VNC on port 5901
• Custom TCP service on any port you like

Multiple services can be installed on same box, also there is free iOS app which can set up your Pi to send you push notifications.


The homepage says it adds the power of remote connections & mobile to your Raspberry Pi in as little as 15 minutes. 

1.1 Manually Installation



[email protected] ~ $ wget https://github.com/weaved/installer/raw/master/binaries/weaved-nixinstaller_1.2.13.bin
--2015-10-06 12:45:16--  https://github.com/weaved/installer/raw/master/binaries/weaved-nixinstaller_1.2.13.bin
Resolving github.com (github.com)... 192.30.252.129
Connecting to github.com (github.com)|192.30.252.129|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://raw.githubusercontent.com/weaved/installer/master/binaries/weaved-nixinstaller_1.2.13.bin [following]
--2015-10-06 12:45:19--  https://raw.githubusercontent.com/weaved/installer/master/binaries/weaved-nixinstaller_1.2.13.bin
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 199.27.76.133
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|199.27.76.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 303036 (296K) [application/octet-stream]
Saving to: `weaved-nixinstaller_1.2.13.bin'

100%[=============================>] 303,036      665K/s   in 0.4s  


2015-10-06 12:45:23 (665 KB/s) - `weaved-nixinstaller_1.2.13.bin' saved [303036/303036]


[email protected] ~ $ chmod +x weaved-nixinstaller_1.2.13.bin

[email protected] ~ $ ./weaved-nixinstaller_1.2.13.bin
Extracting Weaved Software into /home/pi
Finished extracting

You are running installer script Version: v1.2.13

Last modified on February 26, 2015, by Mike Young.

Now launching the Weaved connectd daemon installer...

.
We have detected an arm7l processor.
Is this a Raspberry Pi 2? [y/n] y
Detected platform type: pi
Using /var/log/syslog for your log file

Checking for compatibility with Weaved's network...


Checking if DNS works ... .[OK]


Checking TCP connectivity to weaved.com...<oip=192.168.2.250> [OK]


Send to 174.36.235.146:5960 [] [mip=216.165.201.211] [oport=59612 mport=59612] [no remap] [preserve port] [OK]


Congratulations! Your network is compatible with Weaved services.



*********** Protocol Selection Menu ***********

*                                             *
*    1) SSH on default port 22                *
*    2) Web (HTTP) on default port 80         *
*    3) WebIOPi on default port 8000          *
*    4) VNC on default port 5901              *
*    5) Custom (TCP)                          *
*                                             *
***********************************************

Please select from the above options (1-5):

1
You have selected: 1.

The default port for SSH is 22.

Would you like to continue with the default port assignment? [y/n] y
We will install Weaved services for the following:

Protocol: ssh

Port #: 22
Service name: Weavedssh22



Please enter your Weaved Username (email address):

[email protected]

Now, please enter your password:

Copied notify.sh to /usr/bin
Copied notify_Weavedssh22.sh to /usr/bin
Copied weavedConnectd to /usr/bin
startweaved.sh copied to /usr/bin
no crontab for root
no crontab for root




Your device UID has been successfully provisioned as: 80:00:00:05:46:00:52:0F.


Pre-registration of UID: 80:00:00:05:46:00:52:0F successful.



We will now register your device with the Weaved backend services.

Please provide an alias for your device:
jrasp
Your device will be called jrasp.

Registering Weaved services for Weavedssh22 ................



Starting Weavedssh22...

WeavedConnectd built Feb 26 2015 at 10:53:39 Now Starting Up
   Version 2.11 - (c)2015 Weaved, Inc. All Rights Reserved
   Built with UPNP NATPMP ALIGN BCASTER MALLOC_POOL LINUX RESOLVE BIGBUF pool=262144
   Weaved Development Kit Version based on    Rasberry Pi Version
config file /etc/weaved/services/Weavedssh22.conf
Starting up as daemon
PID file specifed as /var/run/Weavedssh22.pid
setting web config port to dest_server_port 80




**************************************************************************

CONGRATULATIONS! You are now registered with Weaved.
Your registration information is as follows:

Device alias:

jrasp

Device UID:

80:00:00:05:46:00:52:0F

Device secret:



The alias, Device UID and Device secret are kept in the License File:

/etc/weaved/services/Weavedssh22.conf

If you delete this License File, you will have to re-run the installer.


**************************************************************************



Starting and stopping your service can be done by typing:

"sudo /usr/bin/Weavedssh22.sh start|stop|restart"
[email protected] ~ $






By click your device name, Weaved website will give you a new host name and ports for you to do remote connection from anywhere on Internet.




1.2 use apt-get to do auto installation

sudo apt-get update
sudo apt-get install weavedconnectd
sudo weavedinstaller
.
//after entered required information, it will list all registed services
// You will be prompted a menu to choose what you intend to do
=========================================================
Protocol        Port    Service         Weaved Name
=========================================================
TCP             3389    xrdp            xrdp-pi
SSH             22      sshd            jrasp-ssh


********************** Main Menu ************************

*                                                       *
*       1) Attach/reinstall Weaved to a Service         *
*       2) Remove Weaved attachment from a Service      *
*       3) Exit                                         *
*                                                       *
*********************************************************

Please select from the above options (1-3):



2. Dataplicity

If your Raspberry Pi is connected to the internet, you can access it via Dataplicity from anywhere through Internet. You can even connect to devices behind firewalls without needing complex network configurations. Dataplicity connects using client-initiated HTTPS, so it's safe, encrypted and you don't need to make specific firewall exceptions. Dataplicity's homepage says only 60 seconds you can have your Pi to be ready for controlling from anywhere. Of course, it will take longer than 60 seconds but you will not wait more than 5 minutes. Here are all outputs with my test:


login as: pi
[email protected]'s password:
Linux raspberrypi 3.18.7-v7+ #755 SMP PREEMPT Thu Feb 12 17:20:48 GMT 2015 armv7                                                                                                                       l

The programs included with the Debian GNU/Linux system are free software;

the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent

permitted by applicable law.
Last login: Sat Oct 10 10:18:58 2015 from 192.168.2.120
[email protected] ~ $ curl -s https://dataplicity.com/1c7196e9.sh | sudo sh
Welcome to the Dataplicity Shell Quick Install
This may take up to 15 minutes on some systems, but often < 30 seconds

 [step 1 of 5] updating system...

Selecting previously unselected package python-medusa.
(Reading database ... 77461 files and directories currently installed.)
Unpacking python-medusa (from .../python-medusa_1%3a0.5.4-7_all.deb) ...
Selecting previously unselected package python-pkg-resources.
Unpacking python-pkg-resources (from .../python-pkg-resources_0.6.24-1_all.deb)                                                                                                                        ...
Selecting previously unselected package python-meld3.
Unpacking python-meld3 (from .../python-meld3_0.6.5-3.1_armhf.deb) ...
Selecting previously unselected package supervisor.
Unpacking supervisor (from .../supervisor_3.0a8-1.1+deb7u1_all.deb) ...
Setting up python-medusa (1:0.5.4-7) ...
Setting up python-pkg-resources (0.6.24-1) ...
Setting up python-meld3 (0.6.5-3.1) ...
Setting up supervisor (3.0a8-1.1+deb7u1) ...
Starting supervisor: supervisord.
Processing triggers for python-support ...
Selecting previously unselected package libossp-uuid16.
(Reading database ... 77687 files and directories currently installed.)
Unpacking libossp-uuid16 (from .../libossp-uuid16_1.6.2-1.3_armhf.deb) ...
Selecting previously unselected package uuid.
Unpacking uuid (from .../uuid_1.6.2-1.3_armhf.deb) ...
Processing triggers for man-db ...
Setting up libossp-uuid16 (1.6.2-1.3) ...
Setting up uuid (1.6.2-1.3) ...
Preconfiguring packages ...
(Reading database ... 77701 files and directories currently installed.)
Preparing to replace libssl1.0.0:armhf 1.0.1e-2+rvt+deb7u14 (using .../libssl1.0                                                                                                                       .0_1.0.1e-2+rvt+deb7u17_armhf.deb) ...
Unpacking replacement libssl1.0.0:armhf ...
Preparing to replace libexpat1:armhf 2.1.0-1+deb7u1 (using .../libexpat1_2.1.0-1                                                                                                                       +deb7u2_armhf.deb) ...
Unpacking replacement libexpat1:armhf ...
Selecting previously unselected package libexpat1-dev.
Unpacking libexpat1-dev (from .../libexpat1-dev_2.1.0-1+deb7u2_armhf.deb) ...
Selecting previously unselected package libssl-dev.
Unpacking libssl-dev (from .../libssl-dev_1.0.1e-2+rvt+deb7u17_armhf.deb) ...
Selecting previously unselected package libssl-doc.
Unpacking libssl-doc (from .../libssl-doc_1.0.1e-2+rvt+deb7u17_all.deb) ...
Selecting previously unselected package python2.7-dev.
Unpacking python2.7-dev (from .../python2.7-dev_2.7.3-6+deb7u2_armhf.deb) ...
Selecting previously unselected package python-dev.
Unpacking python-dev (from .../python-dev_2.7.3-4+deb7u1_all.deb) ...
Processing triggers for man-db ...
Setting up libssl1.0.0:armhf (1.0.1e-2+rvt+deb7u17) ...
Setting up libexpat1:armhf (2.1.0-1+deb7u2) ...
Setting up libexpat1-dev (2.1.0-1+deb7u2) ...
Setting up libssl-dev (1.0.1e-2+rvt+deb7u17) ...
Setting up libssl-doc (1.0.1e-2+rvt+deb7u17) ...
Setting up python2.7-dev (2.7.3-6+deb7u2) ...
Setting up python-dev (2.7.3-4+deb7u1) ...
 [step 2 of 5] installing Dataplicity Core...
id: dataplicity: No such user
/tmp/tmpYpFshT/pip.zip/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriatly and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
/tmp/tmpYpFshT/pip.zip/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriatly and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  python-psutil
0 upgraded, 1 newly installed, 0 to remove and 93 not upgraded.
Need to get 54.4 kB of archives.
After this operation, 264 kB of additional disk space will be used.
Get:1 http://mirrordirector.raspbian.org/raspbian/ wheezy/main python-psutil armhf 0.5.1-1 [54.4 kB]
Fetched 54.4 kB in 10s (5,203 B/s)
Selecting previously unselected package python-psutil.
(Reading database ... 79253 files and directories currently installed.)
Unpacking python-psutil (from .../python-psutil_0.5.1-1_armhf.deb) ...
Setting up python-psutil (0.5.1-1) ...
Processing triggers for python-support ...
 [step 3 of 5] installing Dataplicity...
 [step 4 of 5] registering device 'raspberrypi'...
 [step 5 of 5] starting service...

Dataplicity Shell is now installed!

Your device will be online in a few seconds
Visit https://dataplicity.com/devices/ to manage your device

[email protected] ~ $ Restarting supervisor: supervisord.




After installed the Dataplicity package, you can log in to Dataplicity, select the device you want and access your remote shell. It's that simple! 

Your devices page at Dataplicity Site before installed package




Your Raspberry device shows in the Your devices page


Just click your device name, your browser will show you your Raspberry session. 






3. Raspberry Pi Dynamic IP DNS Update

3.1 install DDclient on Raspberry Pi


sudo apt-get install ddclient

3.2 Configure /etc/ddclient.conf file 
I am using Dynu free dynamic domain update service. Based on what I found the the suggested configuration file from Dynu website, I generated one for myself.












login as: pi
[email protected]'s password:
Linux raspberrypi 4.1.7-v7+ #817 SMP PREEMPT Sat Sep 19 15:32:00 BST 2015 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Dec  4 22:43:54 2016 from 192.168.2.13
[email protected]spberrypi ~ $ cd /etc
[email protected] /etc $ sudo cat ddclient.conf

daemon = 60
syslog=yes                                                   # Lheck every 60 seconds.
mail=root                                                    # Mail all msgs to root.
mail-failure=root                                            # Mail failed update msgs to root.
pid=/var/run/ddclient.pid                                    # Record PID in file.
use=web, web=checkip.dynu.com/, web-skip='IP Address'        #Get ip from server.
server=api.dynu.com                                          # IP update server.
protocol=dyndns2
login=jonnet                                                 # Your username.
password=12345678                               # Password or MD5 of password.
51sec.DYNU.COM                                  # List one or more hostnames one on each line.
91sec.dynu.com
#MYDOMAIN.COM

[email protected] /etc $


3.3 Run ddclient as a daemon
Since we don't just want the IP address to update once, we still need to set up ddclient to run as a daemon so it can check for a change of IP address periodically and notify the dynamic DNS provider if necessary.
To start the daemon we need to open another configuration file, /etc/default/ddclient and set:
run_daemon="true"
You will notice there is a daemon_interval parameter there too, I think the default value of 300 seconds (5 minutes) is reasonable, so I didn't change it.
Save and close the file, and then run:
sudo service ddclient start
to start the daemon, and:
sudo service ddclient status
to check its status.
ddclient keeps a cache of your IP address, and it will only update the record with your dynamic DNS provider if your IP address hasn't changed. Since some ISPs seem to only allocate new IP addresses when the modem is power cycled, and some dynamic DNS providers will time out if you don't update the record in a while, there is one thing left to do - we need to add a cron job to force an update weekly, just in case.
Choose whether you want to force an update daily or weekly, and then create a file called ddclient in the relevant directory, e.g. /etc/cron.daily or /etc/cron.weekly:
sudo nano /etc/cron.daily/ddclient
Fill in this information:
#!/bin/sh
/usr/sbin/ddclient -force
Then make the script executable:
sudo chmod +x /etc/cron.daily/ddclient
Done :)

Note: For how to get your public ip address from Linux Command line
using curl or wget  extract the information from public site:
curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'  
or 



wget http://ipinfo.io/ip -qO -



Reference:




No comments:

Post a Comment