[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: detecting network change.



On Mon, Jan 12, 2026 at 11:07:59AM +0000, Tim Woodall wrote:
> Is there a portable (not specific to how networking is configured) way of
> detecting a network change and forcing ssh to close.
> 
> At work I have an ubuntu laptop, when at my desk I'm using wired connection,
> when I go to a meeting it switches to wifi.
> 
> All my ssh sessions hang when this happens. Obviously, I can close them with
> <cr>~. and then reconnect, but I'm wondering if there's a neat way to
> automate the disconnect? Sometimes I'm waiting for a job to finish and the
> terminal never updates because nothing tries to transmit. It might be hours
> before I notice because I'm missing that flicker when something happens.
> 
> (I'm using screen to reestablish the session, that part is all working, it's
> just the explicit disconnect I want to automate)

What I do is to set a ServerAliveInterval in my ssh sessions.

Actually, I do it for a different reason: NAT table entries dropped
for sessions with longer inactivity periods. But the client seems (?)
to notice when connection times out, so it /might/ help in your case.

Worth a try:

  ssh -o ServerAliveInterval=60 <myhost>

Cheers
-- 
tomás

Attachment: signature.asc
Description: PGP signature


Reply to: