On 12/01/2026 11:07, 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.
Are the wired network and the wifi network the same network (i.e. can you consider wired and wifi as just different ways of accessing the same network)? If so, then you might consider creating a bond between the two interfaces on your laptop.
With this, you present a single MAC address to the network (implying that your DHCP server, if you have one, only gives you one IP address). The main trick seems to be to configure the bond as an "active-backup" type with the wired connection being the Primary link. This way, when the ethernet cable is disconnected, the WiFi connection is brought up within milliseconds; when the ethernet cable is reconnected, the WiFi will be disconnected in favour of the cable.
As far as other devices on the network are concerned, your single MAC address simply moves from one switch to another and back.
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)
Attachment:
OpenPGP_signature.asc
Description: OpenPGP digital signature