无法连接到亚马逊EC2实例

5

我正在使用AWS - 亚马逊网络服务,并从MAC终端运行命令。

http://ec2-52-xx-x-xx.us-west-2.compute.amazonaws.com

但我遇到了这个错误:

网关超时:无法连接到远程主机

由于此错误,我无法再访问该网站 此实例上应用了安全组 并且ssh的22号端口列在此安全组下


我认为你的意思是无法通过HTTP访问主机。你能否通过SSH连接到它并查找是否实际运行了Web服务器?或者使用AWS控制台停止/启动它,以查看重启是否可以解决问题? - jarmod
我试图通过ssh连接到它,但是系统报错:ssh: 无法解析主机名i: 未提供节点名称或服务名称,或者名称未知。 - Nadosh Al-Ghamdi
这是DNS解析失败的迹象。检查主机名(无论ec2-52-xx-x-xx.us-west-2.compute.amazonaws.com实际上是什么)。您确定您的EC2实例实际上正在运行并且实际上具有分配的公共DNS名称吗? - jarmod
6个回答

3

请检查此实例的安全组(Check the security group for this instance),并尝试通过telnet命令连接IP地址 <允许入站端口>。如果telnet命令在这些端口上执行成功,则表示网络连通。

现在考虑SSH连接问题,默认情况下SSH连接使用22端口,因此您需要检查是否有人更改了sshd_config文件和端口号?


@Nadosh,你之前能够telnet到22端口吗?还是这是一个新的事件? - Niceha

1

端口22用于ssh协议,列在了这个安全组中。

这并不意味着什么。哪些IP地址被允许访问?同时,请检查您的DNS名称是否已更改,如jarmod所建议的。


是的,我知道 DNS 更改了,谢谢。所有 IP 地址都可以访问所有规则,包括 SSH、HTTP、HTTPS 0.0.0.0/0。 - Nadosh Al-Ghamdi
所有规则都设置为任何地方 + 0.0.0.0/0。 - Nadosh Al-Ghamdi

1
简单来说,入站防火墙保护网络免受来自互联网或其他网络段的流量攻击,包括不允许的连接、恶意软件和拒绝服务攻击。出站防火墙则是保护企业网络内部发起的流量免受攻击。

0
你确定主机的名称仍然是ec2-52-xx-x-xx.us-west-2.compute.amazonaws.com吗?每次停止和重新启动Amazon EC2实例时,公共DNS名称都会更改。请在AWS控制台中再次进行确认。

是的,我知道,每次我都会再次复制公共DNS并在浏览器中检查它..谢谢。 - Nadosh Al-Ghamdi
你需要开始调试了。AWS控制台显示实例是否正常?实例的系统日志是否显示异常?假设入站ICMP是开放的,你能ping通主机吗?停止/启动是否可以解决问题?有关其他故障排除选项,请参见http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstancesConnecting.html和https://aws.amazon.com/premiumsupport/knowledge-center/connectivity-linux/。 - jarmod
如何开始调试? - Nadosh Al-Ghamdi
你有按照我之前的帖子中提到的调试选项列表进行工作吗?结果如何? - jarmod

0

检查端口22的入站和出站规则,同时尝试使用分配的IP4地址。


0
To connect using the SSH, ssh should be installed correctly on your machine

just type **"SSH"** if something like this comes up that means your machine has ssh


*usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
           [-D [bind_address:]port] [-E log_file] [-e escape_char]
           [-F configfile] [-I pkcs11] [-i identity_file]
           [-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec]
           [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address]
           [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]]
           [user@]hostname [command]*

Mostly **Linux and macOS X** have already installed if not then go to the
[here][1]  


For **Windows Server** 2019 and Windows 10 [Openssh in Windows][2]


The first check is there any problem with your ssh is allowed from the security group of that particular instance 


like is it allowing to connect from ssh or not

once that is confirmed you have to enter the correct syntax to connect the AWS instance 

Using Public DNS that is available under the running instance

**ssh -i /path/my-key-pair.pem my-instance-user-name@my-instance-public-dns-name**

Using ipv6 similarly, ipv4 can be done

**ssh -i /path/my-key-pair.pem my-instance-user-name@my-instance-IPv6-address**

in place of **my-instance-user-name** you can through documentation provided by AWs[1]


  [1]: http://www.openssh.com
  [2]: https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_overview

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接