我有一个在AWS中运行的EC2实例。当我试图从我的本地盒子ping它是不可用的。

我如何能使实例pingable?


当前回答

确保使用aws ec2实例的公共IP进行ping。 编辑附加到EC2实例的安全组,并为ICMP协议添加入站规则。 尝试ping,如果这个问题没有解决,然后在安全组中添加ICMP的出站规则。

其他回答

有两件事需要考虑。

检查安全组规则。 包括如下所示的入站规则。

类型:自定义ICMPV4, 协议:ICMP, Portrange: Echo Request, 来源:0.0.0.0/0

检查EC2实例的防火墙状态。 在/etc/ufw/before.rules中追加如下内容 -p icmp——icmp-type echo-request -j ACCEPT

terrraform安全组的特定指令,因为-1对我来说不明显。

resource "aws_security_group" "Ping" {
  vpc_id = "${aws_vpc.MyVPC.id}"
  ingress {
    from_port   = -1
    to_port     = -1
    protocol    = "icmp"
    cidr_blocks = ["0.0.0.0/0"]
    ipv6_cidr_blocks = ["::/0"]
  }
}

您必须编辑EC2实例所属的Security Group并允许访问(或者创建一个新的Security Group并将该实例添加到其中)。

默认情况下,一切都被拒绝。您需要添加到安全组的例外取决于您需要向internet提供的服务。

如果它是一个web服务器,你需要允许访问端口80为0.0.0.0/0(这意味着任何IP地址)。

要允许ping实例,您需要启用ICMP通信。

AWS Web控制台在相关下拉列表中提供了一些最常用的选项。

检查你的安全组

2-check Internet网关

3-检查路由表

安全组中的自定义ICMP规则不是它所需要的,至少对我来说是这样。 但下面的规则是可行的:

Type: All ICMP 
Protocol: TCP
Port range: 0 - 65535
Source: Anywhere - 0.0.0.0/0

完成此操作后,您将能够ping其他实例。你会看到如下内容:

PING 10.0.0.15 (10.0.0.15): 56 data bytes
64 bytes from 10.0.0.14: icmp_seq=1 ttl=64 time=3.9 ms
64 bytes from 10.0.0.14: icmp_seq=2 ttl=64 time=3.9 ms
64 bytes from 10.0.0.14: icmp_seq=3 ttl=64 time=10.6 ms
64 bytes from 10.0.0.14: icmp_seq=4 ttl=64 time=40.6 ms
64 bytes from 10.0.0.14: icmp_seq=5 ttl=64 time=3.8 ms
64 bytes from 10.0.0.14: icmp_seq=6 ttl=64 time=5.3 ms
64 bytes from 10.0.0.14: icmp_seq=7 ttl=64 time=6.5 ms
64 bytes from 10.0.0.14: icmp_seq=8 ttl=64 time=3.5 ms
64 bytes from 10.0.0.14: icmp_seq=9 ttl=64 time=21.0 ms
64 bytes from 10.0.0.14: icmp_seq=10 ttl=64 time=3.5 ms
64 bytes from 10.0.0.14: icmp_seq=11 ttl=64 time=3.5 ms
64 bytes from 10.0.0.14: icmp_seq=12 ttl=64 time=59.7 ms
64 bytes from 10.0.0.14: icmp_seq=13 ttl=64 time=3.5 ms
64 bytes from 10.0.0.14: icmp_seq=14 ttl=64 time=3.5 ms
64 bytes from 10.0.0.14: icmp_seq=15 ttl=64 time=4.8 ms
64 bytes from 10.0.0.14: icmp_seq=16 ttl=64 time=3.1 ms
64 bytes from 10.0.0.14: icmp_seq=17 ttl=64 time=3.1 ms
64 bytes from 10.0.0.14: icmp_seq=18 ttl=64 time=3.0 ms
64 bytes from 10.0.0.14: icmp_seq=19 ttl=64 time=3.1 ms

--- 10.0.0.14 ping statistics ---
20 packets transmitted, 19 packets received, 5% packet loss
round-trip min/avg/max = 3.0/9.9/59.7 ms

´s。