You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

EC2实例单网络接口为何同时拥有私有与公网IP?

Understanding EC2 Single Network Interface with Both Private and Public IPs

Great question—this is a super common point of confusion when you’re getting started with AWS EC2, so let’s break it down clearly!

Why a single network interface has both private and public IPs

  • Every EC2 instance in a VPC gets a private IP address by default—this is the actual IP assigned directly to the instance’s network interface (like eth0) at the operating system level. It’s used for all internal communication within your VPC (talking to other instances, RDS databases, subnets, etc.).
  • The public IP isn’t attached directly to your instance’s network interface. Instead, AWS uses a 1:1 Network Address Translation (NAT) setup at the edge of your VPC (via the Internet Gateway). AWS maps the public IP to your instance’s private IP behind the scenes. This lets external traffic reach your instance using the public IP, and any outgoing traffic from your instance gets translated to the public IP so it can communicate with the internet.

Why ifconfig only shows one interface but the instance still works with dual IPs

  • When you run ifconfig (or ip addr on newer Linux distros) inside the instance, you’re only seeing what’s configured at the operating system level. The instance’s OS has no idea about the public IP—your primary network interface (like eth0) only has the private IP assigned to it.
  • All the public IP magic happens in AWS’s own infrastructure, not on your instance. Here’s how the traffic flows:
    • Incoming traffic to your public IP hits AWS’s Internet Gateway, which translates the public IP to your instance’s private IP and forwards the traffic right to your instance.
    • Outgoing traffic from your instance (with the private IP as the source) goes to the Internet Gateway, which swaps the source IP to the public IP before sending it out to the internet.
  • So from your instance’s perspective, it’s only ever using its private IP for all communication. AWS handles the public IP mapping completely transparently—you don’t need to configure anything extra on the instance itself.

内容的提问来源于stack exchange,提问作者Shardool Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 04:52:43