SSH Config – Add Host Section Matching IPs When Using Hostname

dnshostnameipopensshssh

I want a host section in my ssh config that matches any local IP:

Host 10.* 192.168.*.* 172.31.* 172.30.* 172.2?.* 172.1?.*
  setting
  setting
  ...

This works as long as I connect directly to a relevant IP. If I however connect to a hostname that later resolves to one of these IPs, the section is ignored.

sshd has Match Address sections which I think can be used for this, but they won't work in ssh client configs.

Is there any way to achieve this?

Best Answer

You can't do that using only ssh_config options, but there is exec option, which can do that for you:

Match exec "getent hosts %h | grep -qE '^(192\.168|10\.|172\.1[6789]\.|172\.2[0-9]\.|172\.3[01]\.)'"
   setting
Related Question