keep ssh connection alive and persistant while switching network interface connections

Scenario:

  1. At my desk with laptop plugged in to ethernet and connected to remote server over SSH
  2. Want to move to other side of office with laptop and change to WiFi without interrupting SSH connection

I've tried: connecting to WiFi first then disconnecting ethernet; and also disconnecting ethernet first then connecting to WiFi. Neither approach works. Also tried when using Ubuntu and OS X servers along with both OS options as well for the client. No luck.

It seems like I need some way of telling my SSH connection that it should begin using the newly connected network interface instead of the old disconnected interface. Any ideas?

I realize that I could just stay on WiFi the whole day, but I don't want to do that. I also realize that I can just work from within a screen session on the remote server and then re-connect to that screen session after changing interfaces, but I don't want to do that either. For example, I might be piping some big command like a database dump over SSH or I might have files open through SSHFS, or I might just want to avoid the nuisance of re-connecting


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.