Unable to perform sudo apt-get update from EC2 instance
Asked Answered
R

11

10

I am unable to perform sudo apt-get update on by Ubuntu EC2 instance. When I run -

sudo apt-get update

I get the below error:-

Err:1 http://eu-central-1.ec2.archive.ubuntu.com/ubuntu bionic InRelease
  Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (52.59.228.109), connection timed out Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (52.59.244.233), connection timed out Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (18.196.1.133), connection timed out Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (35.158.129.174), connection timed out Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (35.159.12.228), connection timed out Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (52.59.220.169), connection timed out
Err:2 http://eu-central-1.ec2.archive.ubuntu.com/ubuntu bionic-updates InRelease
  Unable to connect to eu-central-1.ec2.archive.ubuntu.com:http:
Err:3 http://eu-central-1.ec2.archive.ubuntu.com/ubuntu bionic-backports InRelease
  Unable to connect to eu-central-1.ec2.archive.ubuntu.com:http:
Err:4 http://security.ubuntu.com/ubuntu bionic-security InRelease
  Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::19). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.88.161), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.162), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.23), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.26), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.149), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.152), connection timed out
Reading package lists... Done
W: Failed to fetch http://eu-central-1.ec2.archive.ubuntu.com/ubuntu/dists/bionic/InRelease  Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (52.59.228.109), connection timed out Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (52.59.244.233), connection timed out Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (18.196.1.133), connection timed out Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (35.158.129.174), connection timed out Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (35.159.12.228), connection timed out Could not connect to eu-central-1.ec2.archive.ubuntu.com:80 (52.59.220.169), connection timed out
W: Failed to fetch http://eu-central-1.ec2.archive.ubuntu.com/ubuntu/dists/bionic-updates/InRelease  Unable to connect to eu-central-1.ec2.archive.ubuntu.com:http:
W: Failed to fetch http://eu-central-1.ec2.archive.ubuntu.com/ubuntu/dists/bionic-backports/InRelease  Unable to connect to eu-central-1.ec2.archive.ubuntu.com:http:
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease  Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::19). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.88.161), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.162), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.23), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.26), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.149), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.152), connection timed out
W: Some index files failed to download. They have been ignored, or old ones used instead.

To fix this issue I followed this and did the below -

sudo sed -i 's/eu-central-1\.ec2\.//g' /etc/apt/sources.list

The I rebooted my system and tried again. Now I get this error on performing sudo apt-get update -

Err:1 http://archive.ubuntu.com/ubuntu bionic InRelease
  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Could not connect to archive.ubuntu.com:80 (91.189.88.161), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.88.162), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.91.23), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.88.149), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.88.152), connection timed out
Err:2 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable)
Err:3 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable)
Err:4 http://security.ubuntu.com/ubuntu bionic-security InRelease
  Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::19). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.88.162), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.23), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.26), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.149), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.152), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.161), connection timed out
Reading package lists... Done
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic/InRelease  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Could not connect to archive.ubuntu.com:80 (91.189.88.161), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.88.162), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.91.23), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.88.149), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.88.152), connection timed out
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic-updates/InRelease  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable)
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/bionic-backports/InRelease  Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable)
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease  Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1562::19). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::17). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::11). - connect (101: Network is unreachable) Cannot initiate the connection to security.ubuntu.com:80 (2001:67c:1560:8001::14). - connect (101: Network is unreachable) Could not connect to security.ubuntu.com:80 (91.189.88.162), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.23), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.26), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.149), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.152), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.161), connection timed out
W: Some index files failed to download. They have been ignored, or old ones used instead.

How do I fix this?

Radioman answered 3/5, 2019 at 11:32 Comment(2)
Do you have internet access, try ping 8.8.8.8Sakhuja
@Sakhuja The ouput of ping 8.8.8.8 is -> PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. What is the issue?Radioman
R
15

I had the same issue and To solve it I had to add another outbound rule to All traffic and set the destination to anywhere. enter image description here

Roxana answered 23/8, 2021 at 7:59 Comment(0)
S
7

It sounds like your instance does not have internet access.

Either your instance needs to be in a public subnet, with a route table to an attached internet gateway:https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Internet_Gateway.html

Or your instance is in a private subnet, which needs a route table to a nat gateway: https://aws.amazon.com/premiumsupport/knowledge-center/ec2-internet-connectivity/

Edit: If you've confirmed the above to be in place then check that the outbound security group rules allow for outgoing internet access on the expected ports.

Sakhuja answered 3/5, 2019 at 16:3 Comment(1)
This is true also does not suffice. To make this work you need also an outbound security rule as mentioned by @FloribertRamentum
G
1

Assuming you have the ec2 in a public subnet with a nat gateway attached. The security group outbound http port 80 rule is required as per the error message. Hope this helps

Geri answered 14/6, 2022 at 13:42 Comment(0)
H
1

I would suggest having a look at the security configurations, namely Security Groups and Subnet NACLs. These are the usual suspects in timeouts and unexplained connection issues - especially if they have not yet been configured or assessed.

For security groups, as there is no incoming connection to the EC2 instance that creates a stateful connection between the update repositories and the server. This means we need to explicitly add an outbound rule to the instance's security group. This can either be a general rule (outbound to everywhere: 0.0.0.0/0 or ::0), or an explicit rule to an expected IP set.

For NACLs, ensure that traffic is being allowed out to everywhere for the NACLs and subnets that traffic will be flowing through. Once again, this could be a general rule (inbound from instance, outbound to everywhere), or a explicit rule to an expected IP set.

Hypogeous answered 13/7, 2023 at 8:49 Comment(0)
W
1

ok that pretty sure that there is some problem with your nat gateway.Conceptually if u will go then ur machine is now is in private subnet and to talk with outside world it needs to talk to internet gateway via nat gateway so this is the problem.Your nat gateway is not getting internet access from internet gateway.so the solution is you just delete your nat gateway and create it again and connect it to public subnet at the time of creation.Next step is go to the route table and attach it to private route table-> edit routes -> and 0.0.0.0/0(allows request from anywhere) and select nat gateway in the dropdown it will automatically show ur crated nat gateway ->click save changes.You are finished just restart your machine run command sudo apt-get update.

Within answered 1/9, 2023 at 16:29 Comment(0)
H
0

Oh got it your ec2 instace need vpc and subnet which you can check from your aws vpc mangement https://ap-south-1.console.aws.amazon.com/vpc/home?region=ap-south-1#subnets: or if you need guidance use https://docs.aws.amazon.com/batch/latest/userguide/create-public-private-vpc.html

Holston answered 23/8, 2021 at 8:6 Comment(0)
J
0

if you already tried all the solution posted then change the region and it will work , I made the exact same steps in two different regions and it worked in one and the other didn't, this problem faced alot of people.

Jadeite answered 10/9, 2022 at 1:49 Comment(0)
M
0

aws use yum e.g

not this

sudo apt-get install git -y

instead

sudo yum install git -y
Miliary answered 13/7 at 11:42 Comment(0)
S
-1

I have a similar issue. The EC2 indeed has Internet access but not able to connect the Ubuntu repos:

root@ip-10-0-8-82:~# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=111 time=1.91 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=111 time=1.94 ms
^C
--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 1.911/1.928/1.945/0.017 ms

root@ip-10-0-8-82:~# host archive.ubuntu.com
archive.ubuntu.com has address 91.189.88.152
archive.ubuntu.com has address 91.189.88.142
archive.ubuntu.com has IPv6 address 2001:67c:1360:8001::23
archive.ubuntu.com has IPv6 address 2001:67c:1360:8001::24

root@ip-10-0-8-82:~# ping 91.189.88.152
PING 91.189.88.152 (91.189.88.152) 56(84) bytes of data.
^C
--- 91.189.88.152 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2032ms

root@ip-10-0-8-82:~# tracepath 91.189.88.152
 1?: [LOCALHOST]                      pmtu 9001
 1:  10.0.0.1                                              0.248ms pmtu 1500
 1:  no reply
 2:  no reply
 3:  no reply
 4:  no reply
 5:  no reply
 6:  100.65.10.1                                           0.552ms asymm  7 
 7:  52.95.65.144                                          1.531ms asymm 13 
 8:  52.95.66.86                                           4.035ms asymm 13 
 9:  52.95.66.163                                          1.765ms asymm 12 
10:  100.92.58.40                                         50.536ms asymm 19 
11:  52.93.135.225                                        48.973ms asymm 18 
12:  150.222.246.119                                      57.410ms asymm 17 
13:  100.91.182.0                                         48.686ms asymm 16 
14:  52.93.9.18                                           50.418ms asymm 19 
15:  52.93.9.37                                           52.182ms asymm 17 
16:  no reply
17:  no reply
18:  no reply
19:  no reply
20:  no reply
21:  no reply
22:  no reply
23:  no reply
24:  no reply
25:  no reply
26:  no reply
27:  no reply
28:  no reply
29:  no reply
30:  no reply
     Too many hops: pmtu 1500
     Resume: pmtu 1500 

I did ran the apt-get update before inside the same EC2 with the same IP address. No changes were made to the EC2 or rebooted. Suddenly it stopped working.

Looks a network/routing issue outside the EC2.

Swellhead answered 25/2, 2021 at 7:23 Comment(0)
C
-1

stop or remove anti-virus software from the local system and stop the firewall. reprocess installation. Now it works fine.

Cerracchio answered 14/3, 2022 at 15:37 Comment(0)
D
-4

I was facing same issue. I have fixed it by changing security rules. just change your setting to default security rules.

Like in inbound only 8080 port and 22 port are configured. delete the rest security laws.

Driest answered 19/11, 2020 at 16:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.