7

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?

1 Answer 1

8

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
3
  • Wouldn't the host or nslookup commands be better for this?
    – muru
    Feb 7, 2016 at 9:23
  • Yes. It would work also, but this is how I know it and ping is more familiar for users :)
    – Jakuje
    Feb 7, 2016 at 9:26
  • 2
    This works, thanks! Here's what I used in the end: Match exec "getent hosts %h | grep -qE '^(192\.168|10\.|172\.1[6789]\.|172\.2[0-9]\.|172\.3[01]\.)'
    – 1N4001
    Feb 7, 2016 at 9:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .