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

bea*_*ito 3 ssh hosts

我已经配置了堡垒或(跳转)框来访问虚拟专用网络。

#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
Run Code Online (Sandbox Code Playgroud)

我能够通过 ssh 进入堡垒和 10.1.1.6 地址,没有任何问题。

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

#/etc/hosts
10.1.1.6    my-host-inside-vpc.corp.internal
Run Code Online (Sandbox Code Playgroud)

但是,当我这样做并尝试访问机器时,我得到以下信息

?  ~ 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.
Run Code Online (Sandbox Code Playgroud)

此时操作超时。

Zor*_*che 5

Host在连接时使用的名称相匹配,DNS解析后的IP地址。

尝试使用Host *corp.internal

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

ProxyCommand ssh bastion -W $(getent hosts $h | cut -d " " -f1):%p
Run Code Online (Sandbox Code Playgroud)