How to automatically switch ssh config based on local subnet?

前端 未结 5 1994
无人及你
无人及你 2021-02-14 15:36

When I\'m on a certain network (subnet is 10.10.11.x) I need to jump through an intermediate host to reach my destination because of destination port I can\'t change and limited

5条回答
  •  温柔的废话
    2021-02-14 16:29

    You can use Match's exec option to execute shell commands, so you can write something like this:

    Match host web exec "hostname -I | grep -qF 10.10.11."
        ForwardAgent yes
        ProxyCommand ssh -p 110 -q relay.example.com nc %h %p
    Host web
        HostName web.example.com
        Port 1111
    

    The Match option boolean logic can short-circuit, so put host first to skip the exec term for other hosts. Try ssh web -vvv to see the Match logic in action.

提交回复
热议问题