简体   繁体   English

无法将 Internet 与私有子网中的 EC2 实例连接起来

[英]Cannot connect internet with EC2 instance in private subnet

I am trying to install docker on my EC2 instance in private subnet which I have SSH using Jumpbox.我正在尝试在我使用 Jumpbox SSH 的私有子网中的 EC2 实例上安装 docker。 I even tried to allow ALL TRAFFIC in my security group, but still didnot happen.我什至试图在我的安全组中允许 ALL TRAFFIC,但仍然没有发生。

sudo yum update -y
Loaded plugins: priorities, update-motd, upgrade-helper
Could not retrieve mirrorlist http://repo.us-west-1.amazonaws.com/latest/main/mirror.list error was
12: Timeout on http://repo.us-west-1.amazonaws.com/latest/main/mirror.list: (28, 'Connection timed out after 5001 milliseconds')


 One of the configured repositories failed (Unknown),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Disable the repository, so yum won't use it by default. Yum will then
        just ignore the repository until you permanently enable it again or use
        --enablerepo for temporary usage:

            yum-config-manager --disable <repoid>

     4. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot find a valid baseurl for repo: amzn-main/latest

An Amazon EC2 instance in a private subnet cannot directly communicate with the Internet.私有子网中的 Amazon EC2 实例无法直接与 Internet 通信。 This is intentional, since it is a private subnet .这是有意为之,因为它是一个私有子网

To allow such connectivity:要允许这种连接:

  • Create a NAT Gateway in a public subnet in the same VPC在同一 VPC 的公有子网中创建NAT 网关
  • Modify the Route Table for the private subnet to direct traffic destination 0.0.0.0/0 to the NAT Gateway修改私有子网的路由表以将流量目标0.0.0.0/0定向到 NAT 网关

When the EC2 instance tries to access the Internet, its request will be sent to the NAT Gateway.当 EC2 实例尝试访问 Internet 时,其请求将发送到 NAT 网关。 The NAT Gateway will make the request on behalf of the instance and will send the response back to the instance. NAT 网关将代表实例发出请求并将响应发送回实例。 This allows outbound connectivity to the Internet while protecting the instance from inbound connectivity.这允许到 Internet 的出站连接,同时保护实例免受入站连接的影响。

It is not strictly necessary to use private subnets.使用私有子网并不是绝对必要的。 Security Groups can perform a similar function at the instance level rather than at the subnet level.安全组可以在实例级别而不是子网级别执行类似的功能。

In this situation, when EC2 is inside VPC and we want to allow EC2 to connect outside world through internet.在这种情况下,当 EC2 在 VPC 内部时,我们希望允许 EC2 通过互联网连接外部世界。 We need to add outbound rules to EC2.我们需要向 EC2 添加出站规则。 For eg, I wanted to download Docker on EC2 from amazom repository.例如,我想从 amazom 存储库下载 EC2 上的 Docker。 I have added HTTP rules in below snapshot我在下面的快照中添加了 HTTP 规则

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 私有子网中的 AWS EC2 实例无法通过 NAT 网关连接到互联网 - AWS EC2 instance in private subnet unable to connect to internet via NAT gateway 尝试从堡垒服务器连接到私有子网中的 EC2 实例 - Trying to connect to EC2 instance in private subnet from bastion server 无法在私有子网中的ec2实例上运行ecs容器 - cannot run ecs container on ec2 instance in private subnet AWS - 无法 ping VPC 中私有子网上的 EC2 实例 - AWS - Cannot ping EC2 instance on private subnet in VPC 如何访问私有子网中的 EC2 实例? - How to access to EC2 Instance in private subnet? AWS VPC - 无法从私有子网中的堡垒主机通过 SSH 连接到不同子网中同一 VPC 中的 EC2 实例 - AWS VPC - Cannot SSH from Bastion Host in private subnet to EC2 instance in the same VPC in a different subnet 如何使私有子网中的 EC2 实例可从 Internet 访问? (如能够访问该网站) - How to make EC2 instance in private subnet accessible from the internet? (as in being able to visit the website) 我们可以通过 Internet 的中转网关访问私有子网中的 EC2 实例吗? - Can we reach an EC2 instance in private subnet through a transit gateway from internet? 如何在 AWS VPC 的私有子网中连接 AWS EC2 实例后面的网页 - How to connect a webpage behind a AWS EC2 instance in a private subnet in a AWS VPC 如何在私有子网中获取 EC2 实例私有 IP? - How to get EC2 instance private IP in a private subnet?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM