我是否需要为我的笔记本电脑设置路由 table 以通过 ssh 连接到具有 public IP 的实例?
Do I need to set up route table for my laptop to ssh to an instance with public IP?
先说一下我的操作步骤:
我使用 CIDR 10.20.0.0/16 设置了一个 VPC(我创建并附加了一个 IGW,igw-14ed6f75)。
然后我设置了一个子网subnet_A 10.20.1.0/24。这个子网的路由table是10.20.0.0/16 -->local
(注意:我没有在这个路由table中设置0.0.0.0/0 --> igw-14ed6f75
的路由)
我在subnet_A启动了一个实例instance_A,它自动创建的publicIP是52.53.245.253
。 (顺便说一句,这个实例使用的密钥对是bastion_box)
我想通过 ssh -i ~/.ssh/bastion_box.pem ec2-user@52.53.245.253
ssh 到 instance_A
- Result/Observation:我不能 ssh 进入instance_A
现在我在subnet_A关联的route-table中添加了一条route0.0.0.0/0 --> igw-14ed6f75
,然后再进行ssh操作ssh -i ~/.ssh/bastion_box.pem ec2-user@52.53.245.253
- Result/Observation:我现在可以成功ssh进入instance_A
这是我的问题:为什么我们需要 0.0.0.0/0 --> igw-14ed6f75
的路由才能成功通过 ssh 进入实例?我以为这条规则是为了实例连接到互联网,而不是为了外部机器连接到子网。
TCP 连接是双向连接。服务器需要能够向客户端发送流量(一旦完成初始握手,两者就无法区分)。没有出口路由,服务器无法将任何数据包发送回客户端以建立连接。
来自 http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Internet_Gateway.html(加粗):
To enable access to or from the Internet for instances in a VPC
subnet, you must do the following:
- Attach an Internet gateway to your VPC.
- Ensure that your subnet's route table points to the Internet gateway.
- Ensure that instances in your subnet have public IP addresses or Elastic IP addresses.
- Ensure that your network access control and security group rules allow the
relevant traffic to flow to and from your instance.
先说一下我的操作步骤:
我使用 CIDR 10.20.0.0/16 设置了一个 VPC(我创建并附加了一个 IGW,igw-14ed6f75)。
然后我设置了一个子网subnet_A 10.20.1.0/24。这个子网的路由table是
10.20.0.0/16 -->local
(注意:我没有在这个路由table中设置0.0.0.0/0 --> igw-14ed6f75
的路由)我在subnet_A启动了一个实例instance_A,它自动创建的publicIP是
52.53.245.253
。 (顺便说一句,这个实例使用的密钥对是bastion_box)我想通过
ssh 到 instance_Assh -i ~/.ssh/bastion_box.pem ec2-user@52.53.245.253
- Result/Observation:我不能 ssh 进入instance_A
现在我在subnet_A关联的route-table中添加了一条route
0.0.0.0/0 --> igw-14ed6f75
,然后再进行ssh操作ssh -i ~/.ssh/bastion_box.pem ec2-user@52.53.245.253
- Result/Observation:我现在可以成功ssh进入instance_A
这是我的问题:为什么我们需要 0.0.0.0/0 --> igw-14ed6f75
的路由才能成功通过 ssh 进入实例?我以为这条规则是为了实例连接到互联网,而不是为了外部机器连接到子网。
TCP 连接是双向连接。服务器需要能够向客户端发送流量(一旦完成初始握手,两者就无法区分)。没有出口路由,服务器无法将任何数据包发送回客户端以建立连接。
来自 http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/VPC_Internet_Gateway.html(加粗):
To enable access to or from the Internet for instances in a VPC subnet, you must do the following:
- Attach an Internet gateway to your VPC.
- Ensure that your subnet's route table points to the Internet gateway.
- Ensure that instances in your subnet have public IP addresses or Elastic IP addresses.
- Ensure that your network access control and security group rules allow the relevant traffic to flow to and from your instance.