在/ etc / hosts或ssh_config中使用别名

我已经configuration了堡垒或(跳转)框来访问虚拟专用networking。

#ssh_config Host bastion HostName 14.90.140.120 User me IdentityFile ~/.ssh/me ForwardAgent yes Host 10.1.* User me IdentityFile ~/.ssh/me ProxyCommand ssh bastion -W %h:%p 

我能够ssh入堡垒和10.1.1.6地址没有问题。

我想要做的是添加一个条目,如下所示。 注意:目前我还没有时间使用DNS,但这将是我的首选方法。

 #/etc/hosts 10.1.1.6 my-host-inside-vpc.corp.internal 

当我这样做,然后尝试访问该机器,我得到以下

 ➜ ~ ssh -vvv my-host-inside-vpc.corp.internal debug1: Reading configuration data /home/me/.ssh/config debug1: /etc/ssh/ssh_config line 19: Applying options for * debug2: ssh_connect: needpriv 0 debug1: Connecting to my-host-inside-vpc.corp.internal [10.1.1.6] port 22. 

此时手术超时。

Host匹配您连接时使用的名称, 而不是 DNSparsing后的IP。

尝试使用Host *corp.internal代替。

根据我们在注释中的讨论,如果您想使用符号名称,但是需要将它们parsing为堡垒主机的IP,那么您可以像这样在ProxyCommand中使用子expression式。

 ProxyCommand ssh bastion -W $(getent hosts $h | cut -d " " -f1):%p