This week I have learned something interesting during my remote work for 4i4.
Consider the case that we have a Raspberry Pi which we must have connection with it through internet. This is a normal problem and the solution is stablishing Secure SHell on the headless board so we will be able to connect remotely. The critical point in our case is that its WIFI network may change time to time and we need the access although the network changes. To maintain consistent access to Raspberry Pi even when its Wi-Fi network changes, we can use a few different approaches:
1. Dynamic DNS (DDNS); 2. Static IP Address3; 3. VPN (Virtual Private Network); and 4. Reverse SSH Tunneling.
The right answer for this case is Reverse SSH Tunneling. With reverse SSH tunneling, Raspberry Pi can initiate an SSH connection to a remote server of 4i4, and then we can connect to the Raspberry Pi through this tunnel from our computers.
To be more accurate we have to use Autossh. Autossh is a utility that helps in automatically re-establishing SSH tunnels in case the connection is interrupted or drops. It is particularly useful in scenarios where you want to maintain a persistent SSH connection, such as reverse SSH tunneling.
In our case, Autossh can be beneficial because we are using reverse SSH tunneling to access your Raspberry Pi remotely and the Wi-Fi network changes, . It ensures that even if the Raspberry Pi’s network connection is interrupted or the IP address changes, the SSH tunnel will be automatically re-established, allowing us to maintain access to the Raspberry Pi.