How to automatically switch ssh config based on local subnet?

前端 未结 5 1996
无人及你
无人及你 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:24

    I'm using the following function for that:

    function ssh() {
      network=`networksetup -getairportnetwork en0 | cut -d: -f2 | tr -d [:space:]`
      if [ -n "$network" -a -f $HOME/.ssh/config.$network ]; then
        /usr/bin/ssh -F $HOME/.ssh/config.$network "$@"
      else
        /usr/bin/ssh "$@"
      fi
    }
    export -f ssh
    

    So I need a separate configuration file for each WiFi network where I want a custom solution. It works for me right now, but it's ugly. I can recommend it only as an idea, not as the best solution.

    I'd be glad to know any better solution.

提交回复
热议问题