SSH 跳板机自动化:在家直连,在外自动走堡垒
source: evertpot.com — 2026-07-21
概述
作者在家中通过 Split-Horizon DNS 使用 .m.example.ca 域名直连服务器,出门时则需通过跳板机。解决方案是在 ~/.ssh/config 中使用 Match + exec 指令:当 getent hosts %h 失败时自动启用 ProxyJump。文章还讨论了 .local 域名走 MDNS 的延迟和安全风险(ForwardAgent 可能泄露整个 SSH 密钥链),建议 .local 主机始终走跳板机以确保安全。
核心要点
- 使用 Match + exec 指令动态决定是否走跳板机:getent hosts %h 失败时启用 ProxyJump。
- Match host *.m.example.ca exec "! getent hosts %h >/dev/null" 仅在外网解析失败时生效。
- 对于 .local / MDNS:ForwardAgent 存在安全风险,恶意主机可模拟 target.local 获取整个 SSH 密钥链。
- ProxyJump 是 比 ProxyCommand 更简洁的跳板指令,已在较新 SSH 版本中可用。
金句
The annoyance with this is that if I use one of the above commands, I always go through the bastion whether I am home or not.
like 0
dislike 0
back to Lobsters