keep ssh connection alive and persistant while switching network interface connections

Solution 1:

I suspect that this solution will not work for SSHFS, etc, but you could take a look at Mosh which provides roaming support for at least the shell itself.

Solution 2:

I'm afraid you cannot do this, by definition. An SSH session runs over a TCP connection, which is defined by the four-tuple (source address, source port, destination address, destination port). You cannot shift the existing connection to a different address on the client (aside from the fact that the OS will tear down the connection when the interface goes down).

NAT may complicate this picture, but not in any way that will help you.


Solution 3:

Old thread, I know, but for sake of completeness since I was looking for the same thing...

In Windows 7 or newer you should simply be able to select both your wifi adapter and Ethernet adapter and choose "Bridge Connection". This will give you a single IP address for both, and you will now be able to disconnect and reconnect Ethernet at will (given continuous wifi coverage).


Solution 4:

I manage this in two ways:

Start the session from a terminal server in your datacenter (RDP/Windows/etc)

OR

Install GNU screen or tmux and start them after login.

I prefer tmux because screen is pretty old school, but if you are only allowed to install supported packages, screen is in the RHEL repo.

OR

Do both.


Solution 5:

The problem is probably that your source IP address changes when you switch between cabled and wifi. This will prevent ssh sessions from coming back.

I handled this in linux by connecting over a vpn and making sure that the vpn connection always gives the same ip to your account (not difficult to enforce, but chance is high that you will receive the same ip over vpn already by default anyway if it's available, but better enforce it to be sure). I mostly use vtun, but openvpn is ok too. Make sure your connections go over the vpn (correct routing, pushed prefixes,...)

I've been able to be offline from the cable for even as long as 5 minutes and then connect to wifi and still be able to stay connected to all my ssh sessions. Ongoing ping, mtr, htop,... just continue when the vpn is restored as if nothing happened.