Search code examples
network-programmingsshraspberry-piremote-accesslte

Remote access from Desktop to RPI behind an LTE Modem and dynamic IP address


I am trying to connect remotely to my RPI Zero2W from my desktop.

Here is the current environment

  1. The RPI and Desktop are on separate networks, the RPI is connected to a LTE Modem and the desktop to a router
  2. The LTE modem changes the IP address every time on startup and does not allow port forwarding
  3. The only known ports that are open on the LTE are port 1883 (MQTT) and port 8883 (MQTTS) --> the router itself provides communication with MQTT protocol

Due to these complicated connection requirements I have not been able to connect remotely to my RPI at all.

The internet suggests various solutions:

  1. Using a VPN: I have tried using wireguard but got stuck on the router port forwarding. In order for the port forwarding to work I would need to know the IP of the RPI connected to a LTE modem, but since the IP is dynamic there is no use using port forwarding, it is not even on the same network.
  2. Using third party apps: I have tried using Ngrok but since it requires port forwarding I am only able to open ports 1883 and 8883, from which 1883 is used for MQTT communication with the server. The only one available is port 8883, but since I want to use ssh I need to use port 22 which port 8883 isn't
  3. SSH tunneling: Again since both sides require port forwarding I have not been able to successfully pull this off either

Solution

  • As per my understanding some ports are open meaning you can connect to those ports from your Desktop provided you know the IP address of the RPi. But from RPi I assume you can connect to other ports such as 443.

    I would suggest this solution:

    On your Rpi, run this command ssh -p 443 -R0:localhost:22 [email protected]. This would give you an address and port using which you can access your RPi from your desktop.

    Now there is a catch, on a restart this address will change. You can do this to figure out the address:

    1. Create a free account on pinggy.io

    2. Use the command on your RPi (replace yourtoken with your pinggy token):

      while true; do 
          ssh -p 443 -R0:localhost:22  [email protected]; 
      sleep 5; done
      
    3. Then from the pinggy dashboard you can always check your present address and port.

    Disclosure: I am a part of Pinggy team