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

时间:2019-04-05 20:53:08

标签: amazon-web-services amazon-ec2 amazon-vpc

我正在尝试在我使用Jumpbox进行SSH的专用子网中的EC2实例上安装docker。我什至尝试允许我的安全组中使用“ 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

2 个答案:

答案 0 :(得分:0)

专用子网中的Amazon EC2实例无法直接与Internet通信。这是故意的,因为它是私有子网

要允许这种连接:

  • 在同一VPC的公共子网中创建 NAT网关
  • 修改专用子网的路由表,以将流量目标0.0.0.0/0定向到NAT网关

当EC2实例尝试访问Internet时,其请求将发送到NAT网关。 NAT网关将代表实例发出请求,并将响应发送回实例。这样可以实现出站与Internet的连接,同时保护实例免受入站的连接。

使用私有子网并非绝对必要。安全组可以在实例级别而不是子网级别执行类似的功能。

答案 1 :(得分:0)

在这种情况下,当EC2位于VPC内部时,我们希望允许EC2通过Internet连接到外部世界。我们需要向EC2添加出站规则。 例如,我想从amazom存储库下载EC2上的Docker。我在下面的快照中添加了HTTP规则

enter image description here