vinnemon
Posts: 4
Joined: Fri Sep 23, 2016 1:16 am

How to remote access Pi connected to 4G hotspot

Fri Dec 09, 2016 3:37 am

Hello,

I recently got a Pi and started playing with it. I have gotten to the point where I can remotely access my pi using the built in ssh software, as long as both the pi and the computer or phone I am connecting with are on the same wifi network. I want to make it so that I can connect my pi to the wifi put out by a Verizon 4G Hotspot and then remotely access the pi using either my home wifi or my phone's 4G. However, whenever I bring 4G into the equation on either end, the remote connection fails. Can anyone tell me how to make this work? Please and thank you!

broe23
Posts: 903
Joined: Thu Jan 28, 2016 9:35 pm
Location: Central IL
Contact: Website

Re: How to remote access Pi connected to 4G hotspot

Fri Dec 09, 2016 4:41 am

Check howardforums.com. Most likely there is a Firewall that Verizon is using to keep people from burning through their allotted usage for the service.
Ren: Now listen, Cadet. I've got a job for you. See this button? Ren: Don't touch it! It's the History Eraser button, you fool! Stimpy: So what'll happen? Ren: That's just it. We don't know. Maybe something bad, maybe something good.

fruitoftheloom
Posts: 19799
Joined: Tue Mar 25, 2014 12:40 pm
Location: Delightful Dorset

Re: How to remote access Pi connected to 4G hotspot

Fri Dec 09, 2016 6:28 am

vinnemon wrote:Hello,

I recently got a Pi and started playing with it. I have gotten to the point where I can remotely access my pi using the built in ssh software, as long as both the pi and the computer or phone I am connecting with are on the same wifi network. I want to make it so that I can connect my pi to the wifi put out by a Verizon 4G Hotspot and then remotely access the pi using either my home wifi or my phone's 4G. However, whenever I bring 4G into the equation on either end, the remote connection fails. Can anyone tell me how to make this work? Please and thank you!
Likely Verizon Block Remote Access, maybe Weaved is a solution ?

https://www.weaved.com/raspberry-pi-remote-connection
adieu

My other Computer is an Asus CS10 ChromeBit running Chrome Operating System.
HP Envy 4500 Wireless Printer supported by HPLIP software in Raspbian Buster.
Raspberry Pi Model 2B v1.1

KarmenJell
Posts: 2
Joined: Fri Dec 09, 2016 11:23 pm
Location: UK

Re: How to remote access Pi connected to 4G hotspot

Fri Dec 09, 2016 11:56 pm

When your phone and raspberry pi are on the same network, you are probably using the private IP address of the pi to SSH, right?
The private IP most probably looks something like 192.168.x.x (Although it could also be something like 10.x.x.x or 172.16-32.x.x).

Now if you want to be able to SSH from outside of your private network, you won't be able to use the private address. Instead you will need to use the public IP address. Your router is probably doing something called Network Address Translation (NAT) which is basically a way of giving all your devices different private IP addresses but the same public IP address.

This is a problem when you want to connect to something specific inside your network from the outside as your router won't know which device to send connect to as they all share the same public address. The way around this problem is to use something called port forwarding.

Another thing that will stop you from SSHing to your pi will probably be some sort of port filtering from your mobile provider. My provider was blocking port 22, which is the default port for SSH. You can change the port number that your pi listens on to get around this. You simply need to change a line in

Code: Select all

/etc/ssh/sshd_config
Here's a guide on how to do that: http://www.linuxlookup.com/howto/change ... t_ssh_port. I changed mine to port 443 as that is not blocked by service providers. (However if you plan on running a web page on port 443 you will probably need to choose a different port number)

To do this, first you will need to set a static (unchanging) IP address for your pi. There are a a couple of ways you can do this. You can follow this guide to set a static IP address:https://www.cyberciti.biz/faq/linux-con ... -tutorial/

Once that is set, you will need to log into your router. You can find a guide on how to do this on your router manufacturers webpage or by simply googling it. The username and password (if you haven't changed it) will probably also be on the website, or written somewhere on the router itself. As an aside, I would HIGHLY recommend changing your router's password from the default one if you haven't done so already.

Once you're logged in, you will need to look for an option called port forwarding. You can then enter the static IP for your pi that you set up earlier in the IP address section. For port number or range, put the number of the port that you also set up earlier. E.g. Mine would be 443 as I set that as the SSH port. If there is an option for protocol just choose TCP or TCP/UDP.

This should then allow you to use your phone on 4G to connect to your pi on your home network. Remember to use the new port number you selected before and to use the public IP address of the pi. You can find this by connecting to your home network and searching "what is my ip" on google. Bear in mind that this can change, so you'll have to check regularly. However sometimes it doesn't change for years.

Note that this method allows your pi to be visible from outside your internal network, i.e the internet. So make sure to use a very strong SSH password and use RSA keys if possible. You can find hardening tips her: https://www.linux.com/learn/5-ssh-hardening-tips.

I think that covers everything. I'll add anything that I remember.
Last edited by KarmenJell on Sat Dec 10, 2016 3:41 pm, edited 1 time in total.

vinnemon
Posts: 4
Joined: Fri Sep 23, 2016 1:16 am

Re: How to remote access Pi connected to 4G hotspot

Sat Dec 10, 2016 1:55 am

Thank you both for the quick input. However, something tells me that Verizon isn't going to be concerned about me burning through my data. My guess is that it has something to do with mobile data having a variable IP address and VNC viewer doesn't trust it.

vinnemon
Posts: 4
Joined: Fri Sep 23, 2016 1:16 am

Re: How to remote access Pi connected to 4G hotspot

Sat Dec 10, 2016 5:12 am

KarmenJell wrote:When your phone and raspberry pi are on the same network, you are probably using the private IP address of the pi to SSH, right?
The private IP most probably looks something like 192.168.x.x (Although it could also be something like 10.x.x.x or 172.16-32.x.x).

Now if you want to be able to SSH from outside of your private network, you won't be able to use the private address. Instead you will need to use the public IP address. Your router is probably doing something called Network Address Translation (NAT) which is basically a way of giving all you devices different private IP addresses but the same public IP address.

This is a problem when you want to connect to something specific inside your network from the outside as your router won't know which device to send connect to as they all share the same public address. The way around this problem is to use something called port forwarding.

Another thing that will stop you from SSHing to your pi will probably be some sort of port filtering from your mobile provider. My provider was blocking port 22, which is the default port for SSH. You can change the port number that your pi listens on to get around this. You simply need to change a line in

Code: Select all

/etc/ssh/sshd_config
. Here's a guide on how to do that: http://www.linuxlookup.com/howto/change ... t_ssh_port. I changed mine to port 443 as that is not blocked by service providers. (However if you plan on running a web page on port 443 you will probably need to choose a different port number)

To do this, first you will need to set a static (unchanging) IP address for your pi. There are a a couple of ways you can do this. You can follow this guide to set a static IP address:https://www.cyberciti.biz/faq/linux-con ... -tutorial/

Once that is set, you will need to log into your router. You can find a guide on how to do this on your router manufacturers webpage or by simply googling it. The username and password (if you haven't changed it) will probably also be on the website, or written somewhere on the router itself. As an aside, I would HIGHLY recommend changing your router's password from the default one if you haven't done so already.

Once you're logged in, you will need to look for an option called port forwarding. You can then enter the static IP for your pi that you set up earlier in the IP address section. For port number or range, put the number of the port that you also set up earlier. E.g. Mine would be 443 as I set that as the SSH port. If there is an option for protocol just choose TCP or TCP/UDP.

This should then allow you to use your phone on 4G to connect to your pi on your home network. Remember to use the new port number you selected before and to use the public IP address of the pi. You can find this by connecting to your home network and searching "what is my ip" on google. Bear in mind that this can change, so you'll have to check regularly. However sometimes it doesn't change for years.

Note that this method allows your pi to be visible from outside your internal network, i.e the internet. So make sure to use a very strong SSH password and use RSA keys if possible. You can find hardening tips her: https://www.linux.com/learn/5-ssh-hardening-tips.

I think that covers everything. I'll add anything that I remember.
Wow, thank you. That was more information than I had ever thought I would be able to find. Just one question before I go through doing all that though... My plan is to wirelessly connect my pi to a 4G hotspot (the hotspot puts out a private wifi signal that my pi can pick up) and then remote access it from my home wifi on my laptop or from my phone using mobile data. Will everything you just said still work in this reversed case where I do not have a router connected to my pi?

klricks
Posts: 6442
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: How to remote access Pi connected to 4G hotspot

Sat Dec 10, 2016 5:58 am

Many if not most broadband 3G/4G providers use a Carrier Grade NAT setup: https://en.wikipedia.org/wiki/Carrier-grade_NAT
This means you get a local IP from behind the providers router(s). 192.168.x.x or 10.x.x.x
If this is the case then it will be impossible to port forward or host any kind of server such SSH VNC or web host etc.
The only option would be to use a service such as Weaved.

Some carriers do offer a static public IP on business accounts.
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

KarmenJell
Posts: 2
Joined: Fri Dec 09, 2016 11:23 pm
Location: UK

Re: How to remote access Pi connected to 4G hotspot

Sat Dec 10, 2016 3:39 pm

I didn't realise you wanted to do it the other way around, I should have read your original post more carefully :?

Yep, what @klricks said. My solution would only work if you don't plan on moving your pi to different networks as you would have to set up port forwarding on routers every time. And as @klricks said, you won't be able to do this on your 4G carriers routers!

JohnnieWalker
Posts: 1
Joined: Mon Oct 08, 2018 7:44 pm

Re: How to remote access Pi connected to 4G hotspot

Mon Oct 08, 2018 7:55 pm

Hi everyone, as a Raspberry Pi noob I stumbled across this ( old ) thread via a Google search, and as I subsequently found a solution I thought I'd sign up and post a solution here, which will hopefully help others :)

I also needed to have the ability to SSH into my Raspberry Pi remotely, I'd already installed teamviewer to allow me to access and control the Pi, but I also needed to figure out an easy way to send commands via SSH remotely.

I discovered the Dataplicity service, it's kind of like a dynamic DNS service for your Pi, except for SSH, just run a command on your Pi and then even when your Pi is in a remote location you can find it and access it via SSH.

It's free for a single device, and they have very affordable plans for multiple devices too.

I'm in no way affiliated with Dataplicity, just trying to help others.

Return to “Beginners”