16

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

2
  • 3
    If you get the same IP address both ways, then this should Just Work. If not, it's pretty much impossible. – Alan Curry Aug 15 '12 at 20:28
  • @AlanCurry If both client and server support MPTCP, then it is possible. But MPTCP support is still very limited, so that's unlikely to be the case. – kasperd Apr 3 '16 at 14:07

10 Answers 10

7

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.

2
  • This looks like a very good solution, but unfortunately it needs to be installed on the server too, which is not always possible due to permissions. – user000001 Oct 26 '18 at 15:18
  • 3
    From mosh.org/#usage mosh --server=/tmp/mosh-server remote_host The user can specify an alternate path for the mosh-server on the remote host. The server binary can even be installed in the user's home directory. – Rouben Jun 19 '20 at 3:54
6

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.

2
  • Yes, but the application can reconnect once it knows that the socket has closed. Does the SSH protocol have a provision to resume an old session? – Ajay Brahmakshatriya Sep 20 '18 at 18:33
  • @AjayBrahmakshatriya SSH has no tools to resume sessions – Ferrybig Aug 16 '19 at 20:55
4

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).

1
  • If doing this, don't cannot to both networks at once, depending on the setup, it kicks everyone in area of the network (source: this happened to me) – Ferrybig Aug 16 '19 at 20:56
3

I manage this in two ways:

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

OR

Install GNU or 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.

2
  • 1
    tmux is really handy. Running remote stuff inside of tmux is an excellent habit to get into. – chicks Apr 3 '16 at 15:01
  • Yes, I agree. The multiple window function is great. – Doug Apr 3 '16 at 15:17
2

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.

1

It can't be done easily.

I can point you at a number of very expensive applications that allow you to keep a telnet or SSH session when moving between IPs or APs, or even for periods of extended periods network disconnection, but they basically achieve this by creating an always-open server-side session for the client machine so the server doesn't know the connection's different or dropped.

I suppose you could code up such a thing, but I imagine that if it was easy to do, my clients wouldn't be getting raped with 5 figure costs for keeping their terminal connections open on wireless handheld scanners.

Though, I did stumble across screen, which claims to create persistent SSH sessions, which may actually work... give it a shot.

1

You can bond the Ethernat and Wifi connections.

This is how I do it on RHEL:

# Run as sudo:
$ sudo -i

$ modprobe bonding

# To enable after reboot, add " bonding " to:
$ vi /etc/modules-load.d/bonding.conf

# Get your network interfaces IDs
$ nmcli device status | grep -E "wifi|eth"
  # enp0s31f6   ethernet  connected  
  # wlp58s0     wifi      connected  

# Add new connections
$ nmcli connection add type bond ifname bond0 con-name My-Connections-Bond
$ nmcli connection add type ethernet ifname enp0s31f6 master My-Connections-Bond con-name My-Eth-Connection
$ nmcli connection add type wifi ifname wlp58s0 master My-Connections-Bond ssid My-SSID con-name My-Wifi-Connection
  
# Add your Wifi credentials
$ nmcli connection modify My-Wifi-Connection wifi-sec.key-mgmt wpa-psk

$ nmcli connection edit My-Wifi-Connection

    nmcli> set wifi-sec.psk YOUR-PASSWORD  
    nmcli> save
    nmcli> quit

# Enable the connections
$ nmcli connection up My-Connections-Bond
$ nmcli connection up My-Eth-Connection
$ nmcli connection up My-Wifi-Connection
  

This should allow you to roam between your Wifi and Ethernet connections, and keep your current SSH, VPN, etc. sessions connected.

Credits to: https://fedoramagazine.org/bond-wifi-and-ethernet-for-easier-networking-mobility/

0

Try being only on wifi when you first start the ssh session. Then plug your ethernet in. That should allow new connections to go over the ethernet, but the established connection will remain on wifi. At least I have seen it work like this with OSX, so OS/hardware may vary.

0

I'm pretty sure you can do this with some silly amount of hacking w/ VMs and Tunneling.

This is untested, but let me know if it does indeed work.

  1. Create a guest VM that has 2 interfaces, 1 bridged adapter (to wifi) and 1 host only networking
  2. Lets say the VM has 192.168.0.25 for the bridged adapter to the wife and 192.168.56.5 to the host only.
  3. Within the vm create the ssh connection w/ a tunnel to the remote side's port 22 ssh -L 10022:remote.server.example.com:22
  4. Now connect through the tunnel. ssh 192.168.56.3 -p 10022
  5. When you lose your wifi connection, change the adapter on the VM over to the ether net adapter .
  6. Hopefully it doesnt hup or screw up the routing table

let me know if it works.

-1
  1. Android phone with decent hardware (samsung10+) 2 . Install VMOS apt on phone for rooted vm environment or use any VM for the laptop connection but use VirtualBox because this is the sefret way
  2. Boot into live Linux OS like NST
  3. Use the hot spot option on your phone, (Android 10) along with bluetooth Hotspot and also usb tether from phone to all visitors. All simultaneously connecting to your phone as the main network source or allowing connections to pass on Linux VM while using phone and wifi connections at the same time
  4. Make a dev windows 10 os on hyper-v and run all 3 devices together as in all network options are connected (pan, eth0, wlan0, usbnet) hot spot, repeater, and usb tether from phone, also hot spot and usb tether on win10 dev VM with wifi and another hot spot from dev os win10 settings
  5. Easier to use tor and i2p for quicker setup but not needed
  6. Run ssh on all 3, or connect using normal ssh connection preferences. This should give you wingspan abilities to fly like an eagle

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.