ssh使用/ etc / hosts文件中的主机名进行隧道传输

我正试图通过跳转框ssh到目标主机。 以下是我的configuration文件条目

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

当我用IP地址SSH到目标地址框时,这工作正常。 但是,当我想与主机名SSH,这将无法正常工作。

注意:我在/ etc / hosts文件中也input了一个条目。

有人可以请帮助如何configuration.ssh / config文件,以便我可以通过查看我的/ etc / hosts文件中的主机名条目使用主机名ssh到目的地框。

使用-W

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

它将从本地机器parsing主机名,而不是从跳箱中parsing主机名。

它还会检查你的主机是否在/etc/hosts提到。

解决此问题的另一种方法是在本地计算机和跳转块/ etc / hosts文件上创build主机名/ IP映射条目。

防爆。 让我们假设您要代理的机器是10.xx.yy.zz,并且您想提供一个用户友好的名称appserver.mycompany.com,您的Jumpbox是jumpbox.mycompany.com。

1)在您的localhost / etc / hosts上,进行以下input

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

2)在您的跳转盘的/ etc / hosts上,进行以下input

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

现在,您的本地机器和您的跳箱将能够解决用户友好的名称到实际的IP和您的SSH代理应该与以下configuration

 Host appserver.mycompany.com User surendra IdentityFile ~/.ssh/id_rsa ProxyCommand ssh -A [email protected] -W %h:%p