1

I have two different environments (production and develop) that both contain a box that have the same local DNS record ie: foo.example.com.

I would like to make an entry in my SSH Config similar to the following so that I can just use a wildcard to catch all the different service names and have it magically resolve to the proper DNS record. (Ignore the part that this will have issues with the known_hosts file, and the lack of ProxyJump related stuff)

Host *.prod *.dev
  HostName %h.example.com

This way I can just do ssh foo.dev or ssh foo.prod and as long as the local DNS record exists for those entries, it should just work. However, doing it this way with the %h it includes the ending portion from the Host, as in, it ends up getting resolved to foo.dev.example.com and not foo.example.com. I'd much rather do it this way so I don't need to create specific entries for every box in each environment in the SSH Config file, but instead just need to update DNS records in each environment when needed.

I have a feeling that the Match keyword is what I want to do to extract the name before the ., but I need it to work in Unix, Linux, and in Windows so solutions using tools like sed won't work.

I've tried to follow along with the man page, but without success. And my google-foo is failing me.

Any help would be greatly appreciated!

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
rjoyce
  • 9
  • 4

1 Answers1

1

You might be able to achieve just that by using ProxyCommand.

Depending on how you want to scale this out (growing number of applications and / or environments) there can be a better alternative. Though with the information you gave, I would proceed like so

Host *.prod *.dev
    ProxyCommand ssh `echo %h | cut -d. -f1`
    [...] # Your other configurations

More information can be found here

Bleacks
  • 31
  • 4