大网数据广告活动
服务器运维问答

NAT gateway for ec2 instances

· 52CE 我爱测

I have a public subnet with ec2 instnaces. The route table has 0.0.0.0/0 IGW (Internet Gateway) as default. I tested adding a public IP address to my instance ( 104.27.142.41/32 as reported by curl ifconfig.co ) and when I ssh to…

问题原文

原帖链接 · tk0221 · CC BY-SA 4.0

I have a public subnet with ec2 instnaces. The route table has 0.0.0.0/0 IGW (Internet Gateway) as default.

I tested adding a public IP address to my instance (104.27.142.41/32 as reported by curl ifconfig.co) and when I ssh to that ec2 it returns this IP address, which I expected.

1) My question is since NAT is only for outbound traffic, how they communicate when it sends request or quote to other sites?

2) If I switch IGW (internet gateway) to NAT for public subnet will it mask all outbound traffic to NAT IP address and still able to communicate with other sites?

已采纳解答

原帖链接 · MLu · CC BY-SA 4.0

Generally you will have 2 kinds of subnets in a VPC:

  1. Public subnet

    • has IGW and optionally NAT
    • 0.0.0.0/0 there points to the IGW
    • hosts (EC2 instances) must have public IP or elastic IP attached as they go directly to the internet
    • hosts can be contacted from the internet on this public/elastic IP (if Security Group permits)
  2. Private subnet

    • has no IGW or NAT
    • the 0.0.0.0/0 points to the NAT in the public subnet above
    • hosts only have private IP and all outbound access is "masked" to the NAT gateway IP
    • hosts can initiate connections to the internet but can't be contacted from outside as they are "hidden" behind the NAT (Network Address Translation gateway).
    • without NAT configured hosts won't have internet access

Hope that explains it :)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-10-11)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。