我有一个在AWS中运行的EC2实例。当我试图从我的本地盒子ping它是不可用的。
我如何能使实例pingable?
我有一个在AWS中运行的EC2实例。当我试图从我的本地盒子ping它是不可用的。
我如何能使实例pingable?
当前回答
安全组使您能够控制到实例的流量,包括可以到达实例的流量类型。
1. Check the Security Groups (Enabled the PORTS to be OPEN)
2. Check the correct VPC
3. Attached the correct Subnet
4. AWS EC2 to be in Public Subnet
5. Enable Internet Gateway
打开AWS EC2中的端口,检查此链接正式的AWS链接
其他回答
虽然晚了几年,但希望这能帮助到其他人……
1 -首先确保EC2实例有一个公共IP。
如果有一个公共DNS或公共IP地址(下面圈出来),那么你应该是好的。这将是你ping的地址。
2 -亚马逊网络规则
接下来,确保Amazon网络规则允许Echo请求。进入EC2的安全组。
右键单击,选择入站规则 A:选择“添加规则” B:选中“自定义ICMP规则- IPv4” C:选择“Echo Request” D:选择“任何地方”或“我的IP” E:选择保存
3 -访问控制列表(如适用)
注:谢谢santosh的这一个。
您的VPC连接到一个网络,这个网络可能也有一些acl阻止它。
A: Go to the Your VPCs --> Default --> Network ACLs --> Details(Tab) --> and select the Main network ACL. (it should bring you to Network ACLs with the network id filter applied) B: Then Select the Network ACL ID (screenshot not shown) C: Under Inbound rules tab, if the current rules don't already allow ICMP, then select Edit Inbound Rule --> Add a New Rule D: Select All ICMPs - IPv4 E: Select Anywhere or type another network CIDR F: Select Allow (0.0.0.0/0 is all) G: Select Save Changes H: do the same for Outbound rules tab (if needed)
4 - Windows防火墙例外:
接下来,Windows防火墙会默认阻止入站Echo请求。通过创建windows防火墙异常允许Echo请求…
点击“开始”,输入“高级安全的Windows防火墙” 选择入站规则
完成了!
希望您现在能够ping通服务器。
有两件事需要考虑。
检查安全组规则。 包括如下所示的入站规则。
类型:自定义ICMPV4, 协议:ICMP, Portrange: Echo Request, 来源:0.0.0.0/0
检查EC2实例的防火墙状态。 在/etc/ufw/before.rules中追加如下内容 -p icmp——icmp-type echo-request -j ACCEPT
那些刚接触aws ec2并希望从SSH、browser、Ping从系统访问实例的人,那么下面是这些的入站规则
如果你想通过SDK以编程方式启用ping(从任何地方),神奇的公式是:
cidrIp: "0.0.0.0/0"
ipProtocol: "icmp"
toPort: -1
fromPort: 8
例如,在Scala(使用AWS Java SDK v2)中,以下工作用于为authorizeSecurityGroupIngress端点定义IpPermission。
val PingPermission = {
val range = IpRange.builder().cidrIp( "0.0.0.0/0" ).build()
IpPermission.builder().ipProtocol( "icmp" ).ipRanges( range ).toPort( -1 ).fromPort( 8 ).build()
}
(我只在EC2-Classic上尝试过。我不知道在VPC下可能需要什么出口规则)
安全组中的自定义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。