Right now I have the following ~/.ssh/config to reach an embedded device via its link-local IPv6:

Host someDevice
    # Hostname fe80::dcad:beff:feef:cafe%%eth0
    Hostname fe80::dcad:beff:feef:cafe%%enxf875a44106f9
    User root
    [some more options...]

I don't want manual interaction every time my network interface changes.

  • With both commented in, SSH will simply use the first.
  • Using a different host for each is impractical.

Has anyone already automated this?

Right now, I'm looking into match as well as /etc/hosts file to achieve this. I prefer, if the configuration happens in the SSH config file.

  • 1
    What kind of embedded device is it? Does it perhaps respond to multicast DNS (mDNS or LLMNR)? Then you could simply use the hostname of the target device, and wouldn't need to worry about the address or the interface name. Aug 8, 2023 at 11:50
  • 4
    Does this answer your question? Use two different ip addresses per host in SSH Check the solution with Match adjusting the detection logic in the exec part. It could be a ping for example. Aug 8, 2023 at 12:07
  • @JohanMyréen Good point, I used that before. Right now I'm tinkering with the network and device, which resulted in mDns not always being reliable.
    – Mo_
    Aug 8, 2023 at 14:11
  • @EduardoTrápani Not quite. ATM, I fail to find a command for exec behind match. There is no iwgetid for ethernet. But I'm confident I will find a replacement, just didnt succeed by now.
    – Mo_
    Aug 8, 2023 at 14:17

1 Answer 1


If the embedded device supports mDns, this is the easiest way.

If it has to be IPv6: This works, but is not perfect.

# If eth0 is UP, use eth0:
Match originalhost  exec "[ $(ip a | awk '/state UP/ {print $2}' | grep eth) == 'eth0:' ]"
    Hostname fe80:::dcad:beff:feef:cafe%%eth0

# Default is enxf875
Host someDevice
    Hostname fe80::dcad:beff:feef:cafe%%enxf875a44106f9
    User root

Not the answer you're looking for? Browse other questions tagged .