A laptop moves between networks, and the right way to reach a server often depends on where you sit. Since OpenSSH 9.4, ssh_config has a localnetwork criterion for exactly that.
It matches when one of your active network interfaces has an address inside the range you give. The first matching value wins in ssh_config, so I’d put the specific block before the general one:
Match host nas localnetwork 192.0.2.0/24
HostName 192.0.2.20
Host nas
HostName nas.example.com
ProxyJump [email protected]
At home, ssh nas goes straight to the LAN address. On any other network, the first block does not match, so ssh falls through to the second one and hops via the jump host.
You can test both paths without moving: ssh -G nas | grep -E '^(hostname|proxyjump) ' shows what ssh would use right now.
Two things to know. The man page warns that a network address is not a trustworthy signal, since a hotel or café can hand out the same private range as your home router. So use it for convenience, like picking a route, and never to loosen something like host key checking. And older clients do not know the keyword at all, so a shared config breaks on a machine with an OpenSSH older than 9.4.
Further reading: ssh_config man page, OpenSSH 9.4 release notes