• detecting network change.

    From Tim Woodall@3:633/10 to All on Monday, January 12, 2026 12:10:01
    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)

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From tomas@3:633/10 to All on Monday, January 12, 2026 12:30:01
    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


    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Michel Verdier@3:633/10 to All on Monday, January 12, 2026 13:00:01
    On 2026-01-12, tomas@tuxteam.de wrote:

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

    I set it in .ssh/config with 2 other parameters
    TCPKeepAlive yes
    ServerAliveInterval 30
    ServerAliveCountMax 360

    See man ssh_config

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From tomas@3:633/10 to All on Monday, January 12, 2026 13:00:01
    On Mon, Jan 12, 2026 at 12:51:36PM +0100, Michel Verdier wrote:
    On 2026-01-12, tomas@tuxteam.de wrote:

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

    I set it in .ssh/config with 2 other parameters
    TCPKeepAlive yes
    ServerAliveInterval 30
    ServerAliveCountMax 360
    Ah, interesting. If OP wants to know about the disconnect "as early
    as possible", a low value for ServerAliveCountMax (say, 1) seems
    attractive.
    Thanks for chiming in :)
    Cheers
    --
    t


    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Nicolas George@3:633/10 to All on Monday, January 12, 2026 13:00:01
    Tim Woodall (HE12026-01-12):
    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.

    Can you request a VPN with a stable IP? That would avoid the
    disconnections altogether, which is more convenient than detecting them.

    Regards,

    --
    Nicolas George

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Niall O'Reilly@3:633/10 to All on Monday, January 12, 2026 13:10:02
    On 12 Jan 2026, at 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.
    Mosh (https://mosh.org/#techinfo or `apt info mosh`)
    carries persistent sessions over UDP, so that the sessions
    don't hang whenever the client address changes.
    I think it might meet your need.
    /Niall


    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From tomas@3:633/10 to All on Monday, January 12, 2026 13:40:01
    On Mon, Jan 12, 2026 at 11:56:34AM +0000, Niall O'Reilly wrote:
    On 12 Jan 2026, at 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.

    Mosh (https://mosh.org/#techinfo or `apt info mosh`)
    carries persistent sessions over UDP, so that the sessions
    don't hang whenever the client address changes.
    I think it might meet your need.
    Mosh is one of the things I always wanted to try. The idea sounds
    Just Right (TM).
    Cheers
    --


    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Tim Woodall@3:633/10 to All on Monday, January 12, 2026 15:30:01
    On Mon, 12 Jan 2026, 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)




    Thanks all, trying those ssh config settings now.

    I can't use VPN from the in office network. While I can use VPN from the
    guest wifi, I do see annoying latency spikes, much more so than WFH.

    Mosh is something to think about if this doesn't work well. I don't
    really care about having to reconnect, more that I don't realise a
    window has "hung" and will never update.

    I used to be on windows using cygwin and the connections dropped as soon
    as I unplugged the laptop so I'm used to that.

    Tim.

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Henrik Ahlgren@3:633/10 to All on Monday, January 12, 2026 16:20:01
    Tim Woodall <debianuser@woodall.me.uk> writes:

    Mosh is something to think about if this doesn't work well. I don't
    really care about having to reconnect, more that I don't realise a
    window has "hung" and will never update.

    Mosh will let you know by showing "Network is unreachable" at the top of
    the screen (hertbeat every 3 sec), and it has other convience features,
    such as lower latency. It feels very nice when working over slower
    (mobile) network links.

    It may not have undergone as extensive a level of security research as
    SSH itself (for instance, keyboard timing attacks?), but there is only
    one CVE from 2012 in security-tracker.dbo.

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Stefan Monnier@3:633/10 to All on Monday, January 12, 2026 16:40:01
    Tim Woodall [2026-01-12 11:07:59] wrote:
    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

    Beside the various other partial solutions offered (which I also use),
    I find it handy to keep a `killall ssh` command at an easy to
    reach location.


    - Stefan

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Darac Marjal@3:633/10 to All on Monday, January 12, 2026 19:40:01

    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)





    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Michael@3:633/10 to All on Tuesday, January 13, 2026 09:40:02
    On Monday, January 12, 2026 12:07:59 PM CET, 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.

    if you are using NetworkManager, there are always /etc/NetworkManager/dispatcher.d/pre-up.d/ and /etc/NetworkManager/dispatcher.d/pre-down.d/

    you could put a script in /etc/NetworkManager/dispatcher.d/pre-down.d/ that

    kills all ssh clients.

    maybe something like:

    #!/bin/bash
    pkill ssh

    ymmv

    greetings...

    --- PyGate Linux v1.5.2
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)