ssh所需的IP地址与服务器内部显示的IP地址有什么区别?


What is the difference between the IP address needed for ssh, and the IP address that is displayed once inside the server

当我ssh进入我的服务器时,我发出以下命令:

ssh <username>@<ip-of-server>

然后,当我进去时,我看到以下提示:

<username>@ip-<different-ip-address>:

当我在服务器中尝试echo $PS1时,我看到以下内容:

'['e]0;'u@'h: 'w'a']${debian_chroot:+($debian_chroot)}'u@'h:'w'$,它告诉我主机必须不同。为什么它们不一样:ip和host?

我问的原因是,我可以通过ssh访问它,但我不能ping它:

ping <ip-of-server>…导致100%的损失。

所以,我想也许我应该ping另一个ip,然而:

ping ip-<different-ip-address>…也会导致100%的损失。

怎么可能无法ping通,但我仍然可以登录?

私有IP是AWS内部的,即10.x.x.x

你也可以通过调用

来检查

curl http://169.254.169.254/latest/meta-data/local-ipv4

从元数据服务器获取信息。

Public IP(如果已分配)是外部IP。您可以从元数据服务器获得相同的结果。试一试:

curl http://169.254.169.254/latest/meta-data/

如果您的shell提示符是一个问题,您可以在查询公共IP后设置提示符。

IP -of-server可能是服务器的公共IP。Different-ip-address可能是服务器的私有IP。

ping不会从外部通过,除非您通过为实例设置的Security组启用ICMP流量。

可以登录,因为SSH使用的端口在Security组中是打开的(TCP 22),而ICMP没有打开(ICMP)。