1

I am trying to ssh to destination host via a jump box. Below is my config file entry

Host 172.* 
   User surendra
   IdentityFile ~/.ssh/id_rsa
   ProxyCommand ssh -q -A surendra@jump nc -q0 %h %p

This works fine when I SSH to destination box with IP address. But when i am trying to SSH with hostname this will not work.

Note: I made an entry in my /etc/hosts file as well.

Can someone please help how to configure the .ssh/config file so that i can ssh to destination box using the hostname by looking the hostname entry in my /etc/hosts file.

ysdx
  • 1,653
  • 12
  • 13
suru1432002
  • 11
  • 1
  • 2
  • What does the name resolve to when you try? Does it show the correct ip? – Diamond Sep 30 '16 at 10:07
  • since the hostname entry is in my localbox i.e.(/etc/hosts) it didn't resolve to anything. Note: We don't have a internal DNS to resolve the hostname. – suru1432002 Sep 30 '16 at 10:14
  • http://serverfault.com/questions/801395/use-of-alias-in-etc-hosts-or-ssh-config/801407#801407 – Zoredache Sep 30 '16 at 14:19
  • Hi, In my case the /etc/hosts file is like this. 10.10.10.1 abc 10.10.10.2 xyz 10.10.10.3 pqr so what should be the Host naming section should be. – suru1432002 Oct 02 '16 at 07:18

2 Answers2

1

Use the -W:

Match exec grep %h /etc/hosts
    [...]
    ProxyCommand ssh -W  %h:%p -q -A surendra@jump

It will resolve the hostnames from your local machine and not from the jumpbox.

It will also check if your host is mentioned in the /etc/hosts.

Jakuje
  • 9,715
  • 2
  • 42
  • 45
1

Another way to workaround this is to make hostname/ip mapping entries on both your local machine and on the jumpbox /etc/hosts file.

Ex. Let us assume that the machine you are trying to proxy into is 10.xx.yy.zz and you want to provide an user friendly name appserver.mycompany.com and Your Jumpbox is jumpbox.mycompany.com.

1) On your localhost /etc/hosts, make a following entry

10.xx.yy.zz appserver.mycompany.com

2) On your jumpbox's /etc/hosts, make a following entry

10.xx.yy.zz appserver.mycompany.com

Now that both your local machine and your jumpbox will be able to resolve the user friendly name to the actual IP and your ssh proxy should work with following configuration

Host appserver.mycompany.com
   User surendra
   IdentityFile ~/.ssh/id_rsa
   ProxyCommand ssh -A surendra@jumpbox.mycompany.com -W %h:%p
Jay
  • 111
  • 2