Access Your Raspberry Pi From Outside Your Home or Local Network

If you’ve ever tried to set up your Raspberry Pi as an Internet of Things device, you’ll know that unless you jump through some massive hoops, you’re stuck serving web pages and data on your local network. It can be a challenge to access your Raspberry Pi from outside your home or local network.

Getting information from your Raspberry Pi on your phone, or while you’re at work or school . . . it’s nearly impossible. There are lots of ways to work your way out to the internet. They’re often painful: ISP’s block ports, you need to set up port forwarding, you might violate your terms of service with your ISP, and you might need to customize your router.

This tutorial will demonstrate how to access your Raspberry Pi from outside your home or local network using the Ngrok Tool.

ngrok requires very little setup, just a few commands in the terminal, and works very reliably.

This tutorial explains how to access the Raspberry Pi from a remote network connection using PuTTY terminal. We also show Raspbian for Robots users how to use noVNC to access your Raspberry Pi desktop and Shellinabox remotely away from the home network.

Ngrok

Ngrok is secure tunneling service that makes your device available from anywhere online. Tunneling is a way to set up a private line, over a public network like the internet, between two computers. When you set up a tunnel between two computers, it should be secure and private, and able to pass through network barriers like port blocking routers and firewalls. This is a handy service that allows you to tunnel requests from the wide open Internet to your local machine when it’s behind a secure wifi network or firewall. With this platform you can access your Raspberry Pi from outside your home or local network in a very simple way.

You learn more about ngrok and its features from here.

Installing Ngrok

To use Ngrok you need to download ngrok application to your Raspberry Pi. To do that type the following command on your Raspberry Pi terminal:

sudo wget https://dl.ngrok.com/ngrok_2.0.19_linux_arm.zip

and then unzip it using:

sudo unzip ngrok_2.0.19_linux_arm.zip

This completes the installation process.

Sign Up

You will have to sign up to establish a secure connection with your Pi. The free version of ngrok allows you to access one terminal at a time, and assigns a random web address every time you start ngrok. With the free version you will have to generate a host address from your Pi every time you wish to establish a remote connection and share the address with the remote user to access.

To create a ngrok account click here and then click signup to get an authtoken key. This token is necessary if you want your own custom domain doing an online SSH.

After you login to the ngrok site you will get an authtoken key which a combination of a lot characters. You will want to keep this token secret: anyone who has this token will be able to access your Raspberry Pi.

You need to embed this token to your Raspberry Pi in the command line using:

./ngrok authtoken yourauthtoken

Change the yourauthtoken with your own token that you get from ngrok website. You only need to this once for your Raspberry pi and it gets stored in the configuration file.

Ex: ./ngrok authtoken qauXbmyDW8j9D

Now you are ready to connect using ngrok.

With the paid version you will get the options to use multiple simultaneous connections, and access your terminal with custom URL and password protect it. You can use this to access the Raspberry Pi on boot remotely from outside your local network. Examples and guidelines to do these are available here.

Accessing the Pi using Putty From a Remote Network

Type the following command in your Raspberry Pi terminal to enable access Putty Terminal from remote.

./ngrok tcp 22

If your tunnel status is “online” you can open your Raspberry Pi terminal using Putty anywhere. Note the Host Address and the Port Number shown in the picture below; you’ll use these to access the Raspberry Pi.

To open SSH online first open a new putty from any computer that is connected to the internet and then enter your ngrok host address and port number like in the image below and click open.

You will find a Putty Security alert window, when you try to access your Pi from remote for the first time, asking your consent to store the rsa2 key in its cache for future reference. Click Yes and proceed.

Now you have your computer connected to your Pi away from your home/local network.

Accessing The Pi Desktop Using noVNC Remotely

Type the following command in your Pi terminal to access your Pi Desktop using noVNC terminal from remote:

./ngrok tcp 8001

If your tunnel status is online then you can open your raspberry pi terminal using noVNC on a browser from anywhere. Open a browser in any computer or mobile phone that is connected to internet and type the address marked in the image onto the browser’s address bar.

You will see a window prompting to enter the password for the Raspbian for Robots image. The default password is robots1234. Type the password and press Enter.

Now your computer is connected to your Pi away from your home/local network and you can access the files using the noVNC.

Accessing the Pi using Shellinabox From a Remote Network

Type the following command to access Shellinabox terminal remotely:

./ngrok tcp 4200

If your tunnel status is online then you can open your Raspberry pi terminal using Shellinabox on a browser from anywhere.Open a browser in any computer or mobile phone that is connected to internet and type the address marked in the image onto the Browser’s Address bar.

You will see a window prompting to enter the login id and password for the Raspbian for Robots image. The default login id is Pi and the password is robots1234.

Now your computer is connected to your Pi away from your home/local network and you can access the files using Shellinabox!

Conclusion

Now that you’re set up with ngrok, you can access your Pi from remote network. Being able to access your Raspberry Pi from outside your home or local network is crucial for home automation and internet of things projects. Now you can access your Pi from a mobile phone while you’re away, you can access it from a computer or have others access your Pi from outside your network. You’re ready to play around with internet-of-things projects using Pi!

Questions

Got a question? Need some help? Ask away on our forums!