我有一个在AWS中运行的EC2实例。当我试图从我的本地盒子ping它是不可用的。
我如何能使实例pingable?
我有一个在AWS中运行的EC2实例。当我试图从我的本地盒子ping它是不可用的。
我如何能使实例pingable?
当前回答
如果你想通过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下可能需要什么出口规则)
其他回答
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"]
}
}
那些刚接触aws ec2并希望从SSH、browser、Ping从系统访问实例的人,那么下面是这些的入站规则
安全组使您能够控制到实例的流量,包括可以到达实例的流量类型。
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链接
添加一个新的EC2安全组入站规则:
类型:自定义ICMP规则 协议:Echo Request 端口:N / A 来源:你的选择(我会选择任何地方,以便能够从任何机器ping)
当访问ec2实例中的新端口时。你要在两个地方相加。 1. 安全组入端口。 2. 防火墙设置入站规则。