
Step three – Connecting to the SSH tunnel from VPSĪfter we’ve created the tunnel with the command at step 1, Raspberry can be accessed by executing the following command on the VPS: # ssh localhost -p 3333 Pkts bytes target prot opt in out source destinationĬhain FORWARD (policy ACCEPT 0 packets, 0 bytes)Ĭhain OUTPUT (policy ACCEPT 33 packets, 5915 bytes) # iptables -L -vnĬhain INPUT (policy ACCEPT 39 packets, 4642 bytes) In this case we don’t have to do any settings in iptables. My iptables on VPS has the default configuration, so is not dropping any packets. I’ve opened port 3333 in the Firewall on the management web-interface of the VPS. – user and IP address of the VPS, replace with your actual user and IP.We’ll start by setting up the reverse SSH tunnel on the Raspberry Pi by typing in the following command: # ssh -R 3333:localhost:22 3333 – the port used for the reverse SSH tunnel (port should be opened on VPS). Note: We are working with root user, if you are not logged in as root, add sudo in the front of the commands. Step two – Setting up a reverse SSH tunnel It is also very easy to set up and it has a very nice and intuitive interface. I am living in Germany and I chose a VPS solution from At the time I’m writing this article, the solution is very affordable, only 1Euro/month and you get 1Core CPU, 0,5GB and 20GB SSD. Or even better, we can choose a VPS (virtual private server) solution from one of the many providers. For this solution we’d need a Linux computer that will be anytime available and directly accessible from Internet. I would like to be able to access the Raspberry Pi from anywhere, not only from my local computer. I’ll write more about this project in a different post, for now let’s focus on ssh tunnel subject, which is quite a challenging part. The Raspberry Pi is used in a remote house to convert a classic alarm system to a smart alarm (with Internet and SMS functionality). My concrete case where I need this kind of implementation is a Raspberry Pi connected to Internet using a 3G USB dongle. How can you achieve this, I’ll explain you in the following lines. Reverse SSH tunneling allows you to create a connection from the remote computer to a local computer and using this established connection to set up a new connection from your computer back to the remote computer. This computer could be placed behind a firewall or a router (NAT) whose rules or settings cannot be changed.Īn easy and practical solution that could help us in this case is to set up a reverse SSH tunnel on Linux. There are cases when a remote computer could be hard to reach.
#SSH TUNNEL RASPBERRY PI HOW TO#
I can't tell you exactly how to set this up with putty because I don't do windows.įinally, you should be able to connect to 127.0.0.1:8080 on your browser. Secondly you need to tell ssh two pieces of information, the port to forward and the address to forward it to, just use 127.0.01 which refers to the Pi itself. The thing with 127.0.0.1 is it is the localhost address of any particular host, so it can be confusing talking about 127.0.0.1 without mentioning the context of which host you're talking about.įirst you need to set up your ssh connection & verify that it does work. Since port forwarding with ssh is what he asked about, telling him not to use this port is a bit counterproductive.



If your ISP changes your public IP address to then the dynamic DNS is updated with the new public IP address so that continues to map to your machine and your home router continues to map it to your LAN address (192.168.0.111:nnnn).ĭougieLawson wrote:There are three IP addresses. Note that the external port number (pppp) and internal port number (nnnn) don't need to match (depending on the rules your router imposes).ĭynamic DNS means you can give a funky name to your public IP address so that I can visit and the dynamic DNS service automagically maps that to :pppp. Port forwarding takes a port from :pppp and maps it to an internal LAN port on 192.168.0.111:nnnn which is your PUBLIC IP address will tell you your current address (there are other services to do that like ). 192.168.0.111 which is your LAN address assigned by your router on the DHCP request or statically assigned by you defining it in /etc/network/interfaces (or as a static assignment in your router).ģ. Don't disable it, but forget it ever existed unless you are using ssh tunnels with PuTTY or something similar.Ģ. 127.0.0.1 which is the loopback address aka localhost.
