How can I keep SSH sessions alive when the IP changes when switching between Wi-Fi and Ethernet?

2

In Mac OS X Yosemite, I want to be able to create a virtual interface with a Static IP that’s tied to both my Ethernet and Wi-Fi interfaces, so that when I undock my laptop, I don’t lose my SSH connections.

The simple answer of just working off of Wi-Fi isn’t acceptable as the network hits congestion or signal constraints and I get awful lag or drop connections sitting at my desk. Bridging the adapters using Mac OS X’s built in option creates a network loop that I don’t seem to be able to avoid—even using spanning tree—unless I’ve over looked something.

Any suggestions?

**Edit Screen is not a good solution. I already use it on the server side when I'm connected because of this issue. I don't want to lose my ssh connection at all when I switch interfaces, meaning, I don't want to have to reconnect and reauth every time I switch from ethernet to wifi. I usually have upwards of 10 ssh sessions going, and it's a lot to reconnect them all

S. Gene

Posted 2015-02-23T23:12:36.877

Reputation: 23

Why not just configure a static IP address? – David Schwartz – 2015-02-25T09:57:23.877

Answers

5

You can use the screen utility to do keep the session running even after you detach and then you can re-attach to the session. It’s available for Mac OS X, I believe.

More information can be found at howtogeek and rackaid tutorials.


Edit:

Since screen is not what the OP is looking for, Mobile Shell (mosh) would fit the use case perfectly. (This is also mentioned by @lnrdo in another answer on this thread).

Here is Keith Winstein, author of mosh, introducing it in this video.

Although, sometime back, I had difficulties installing mosh on the ssh server when I didn't have sudo access. I don't know if things have changed since then.

norbitwise

Posted 2015-02-23T23:12:36.877

Reputation: 166

Not valid solution. I use screen already in my session on the boxes I connect to. I don't want to drop my ssh connection at all. – S. Gene – 2015-02-24T14:11:57.247

I've updated my answer. Does it help you now? – norbitwise – 2015-02-24T16:43:01.997

It does. Mosh is the way to go. Thanks for your help! – S. Gene – 2015-02-25T15:01:35.147

1

I've not tried it - indeed I don't own a Mac, but I've bumped into this type of problem before over a WAN, and the solution could work for you - Set up a VPN between your Mac and your server - in this way the VPN can reconnect and give you the same VPN address - provided you manage to route your SSH session through the VPN tunnel, the keep-alives built in to SSH will allow the session to work regardless of whether you are using WIFI or LAN or switching between the 2.

Another possibility - and again, no mac, so I'm theorising - would be to provide the same IP address (statically) configured for your LAN IP and WIFI address, and then use some kind of profile switching to ensure that WIFI is turned off whenever you are docked - if thats possible on a MAC. Depending on the complexity of the switching network you have this might or might not upset your switching equipment.

davidgo

Posted 2015-02-23T23:12:36.877

Reputation: 49 152

1

You need something as mosh. It requires both server and client side components, but it works for mobile (roaming) devices.

Screen and tmux may help you continue your work after reconnecting, but mosh keeps you connected/reconnecting. In my experience it also is helpful wen your router has a dynamic IP address.

lnrdo

Posted 2015-02-23T23:12:36.877

Reputation: 111

-3

You can modify some parameters on your sshd.conf file. In particular ClientAliveInterval, which could be set to 60 or 120 and TCPKeepAlive(yes or no).

boris quiroz

Posted 2015-02-23T23:12:36.877

Reputation: 105

This won't work because the IP address of the source changes, to TCPKeepalive won't work. – davidgo – 2015-02-24T03:50:48.773