I set up my Raspberry Pi to run on Linux, and I use it as a portable computer. I'm trying to find a way to maintain SSH across different networks while retaining the ability to manipulate it using SSH alone, from a phone. The SSH session does not have to be uninterrupted. I thought perhaps I could find a way to know what the Raspberry Pi's IP address is so that the phone can connect to it with SSH, and so I ask: Is something similar to nmap that I could use to find out all the occupied IP addresses on the network, using a phone, and find out or predict the Raspberry Pi's address? If not, is there a way to use the same IP address on different wireless networks? If not, how can I achieve this?
There are a number of automatic discovery systems that do this, bonjour/zeroconf/avahi being one of them. It’s using multicast-dns (mDNS) to tell other devices on the same network what services it offers and under which names and connection parameters. On Linux this can be done using Avahi, which allows both automatic service broadcasting as well as manually defining what services it should show.
On the client systems you can use CLI and GUI utilities to list all mDNS devices and their services, but a common way is to just use it’s default method: hostname.local
So if your pi is called “pi”, using mDNS you can always reach it using “ssh pi.local” as long as you are on the same network and nobody else with the same name is online in that network at the same time.
If your on Android there's an app in the Play store (I'm sure it's probably on the I store too) called Fing. It's a network scanner and reports the IP and hostname of all connected clients. Give you PI an easily identifiable hostname and use it to find the IP address.
It wouldn't be very easy to use the same IP on different networks. You'd need to reserve the address in advance to ensure it's not in the DHCP range or in use by another client already connected.
You could use reverse ssh to an intermediate server, which would forward connections on port 22 to a specific port to your pi. On the pi you need to run something like this:
ssh -N -R 2243:localhost:22 server_username@server_ip_address
where 2243 is just an example for a port to use. Server_username username you would use to login into the server.
So once that's set up you would simply log in to to the server via ssh and from there ssh into your pi with something like:
ssh pi_username@localhost -p 2243