Is there any way to abstract IP address during ssh?

3

I have a server which is in the middle of a forest. It is connected to the Internet via a microwave link and an ADSL link.Hence it has two different static IP addresses. Now if there is heavy rain, the microwave link breaks and I should use the much slower ADSL link. And I ping the microwave ip time to time to check if it is up again . But at times, I end up using the very slow ADSL link even if the microwave link is back up. Hence I need a way to automate this in the following way.

1.I need to abstract the IP address of the machine with some other name which when I use ssh or sftp, will poll both the IP and connect me to the best one.

so for eg: if I say ssh -Y name@server, It should first try to connect to the microwave link if it cant, then connect to ADSL.

2.Suppose the first time I connect, the microwave link is down so it connects to ADSL, I need it to dynamically change to the microwave link once it is working again. Is this even possible?

Vivek V K

Posted 2014-06-05T00:19:38.663

Reputation: 141

IP address abstraction is DNS, right? So how about scripting a change to your local hosts file to swap out the IP address for the currently preferred interface? – Brian Adkins – 2014-06-05T00:22:12.787

@BrianAdkins Can you please explain more elaborately? I cannot get what you actually mean. – Vivek V K – 2014-06-05T00:28:31.083

4

MultiPath TCP is one option in development for situations like this: http://www.multipath-tcp.org

– Brian – 2014-06-05T00:44:52.507

@Poul7 ha ha. Thanks it is a server for a Radio Telescope. – Vivek V K – 2014-06-05T01:26:42.140

Answers

3

You should use Mosh (= Mobile Shell). It cannot do point 1, but it can do point 2: from its Web page:

If your Internet connection drops, Mosh will warn you — but the connection resumes when network service comes back.

This is all automatic, no need of human intervention.

So you might solve points 1 and 2 simultaneously by using Mosh on the fast IP, moving to an adjacent terminal to start a regular ssh session on the slow IP when Mosh tells you the connection on the fast IP dropped, all the while keeping an eye on the Mosh terminal for its resumption of normal operation.

Mosh has many more advantages than these, like surviving sleep of the client pc, roaming of the client pc with ensuing changes of IP; it circumvents network lag in echoing typed commands, allows Control-C to work, ...

MariusMatutiae

Posted 2014-06-05T00:19:38.663

Reputation: 41 321

This is a great suggestion and almost solves my problem. But consider I am typing on the fast IP, the link goes down before I could save. I cant retrieve that from the slow IP as both are different sessions. I have to wait for the fast IP to come back or I have to retype everything on the slow IP. What I want is a session transfer of ssh from one IP to another based on the availability of it seamlessly.( I can afford a temporary freeze during reconnection). I don't know if it is possible, But since the physical machines of client and server it should be possible theoretically. Isn't it? – Vivek V K – 2014-06-05T01:36:29.957

@VivekVK The Mosh session will buffer all your input, so you will lose absolutely nothing: this is exactly the kind of accident Mosh was designed to guard against. But no, you will not be able to resume the Mosh session, in the ssh session, as if nothing had happened. Besides, if the ADSl line is so slow, hy would you wish to do anything on it, except for routine maintenance? – MariusMatutiae – 2014-06-05T01:48:10.540

1Can use screen (or similar screen management programs) to separate what your running from the SSH session. You can then re-attach to the screen session if the SSH session drops or even pass the screen session to a different SSH session. – Brian – 2014-06-05T03:27:35.760

1@VivekVK The comment above is not correct: what survives is the screen/tmux session, not the ssh connection inside the screen/tmux session. The ssh session disconnects after some time, if the client/server change IP addresses, if the server disconnect for long enough... – MariusMatutiae – 2014-06-05T05:38:05.263

0

Well if the IPs are static, you for sure know which one belongs to each link.

You can assign multiple names to the same machine.

At your DNS records, create a record like microwavehost.domain.com and attach it to your fast IP. Then create a second entry for the secondary ADSL IP adslhost.domain.com.

Now you can try first

ssh -Y name@microwarehost.domain.com
if [ $? -ne 0 ]; then
  echo "WARNING: Using slow ADSL link"
  ssh -Y name@adslhost.domain.com
fi

cavila

Posted 2014-06-05T00:19:38.663

Reputation: 111

This wont do the number 2 requirement that I mentioned above right? For eg if the microwave link is up a minute after I connected, I will still be using the same ADSL. I want a way that ssh can recognize its the same machine on both links and switch over to the faster one when it is available. – Vivek V K – 2014-06-05T00:46:08.467

I think that ssh can not do that. Once a connection is opened(TCP connection open) it can not change it to use another IP address. I guess that you need to reopen a new connection. For that you would need to setup several IPs to same name. But DNS will only give you one in answer. You can create a polling scheduler at your client to kill slow ssh session and reopen a faster one. – cavila – 2014-06-05T01:04:41.997

If I automatically kill the ssh then I would lose whatever I have not saved right? I can give a warning in another terminal by polling the IP and I can manually save and restart. Thats what I am currently doing. But I want it to be automated. Even if the ssh is disconnected and reconnected for the other IP, cant the ssh session state be saved and forwarded through the other IP?? so that I can wait for a 5 second freeze where the ssh reconnects and start working again? – Vivek V K – 2014-06-05T01:13:00.277

2You can use a screen/tmux session to work around the ssh session being killed off and losing data – Lawrence – 2014-06-05T01:32:05.357