Skip to content

Instantly share code, notes, and snippets.

@yggi
Created April 18, 2016 08:14
Show Gist options
  • Save yggi/cbb25f2d570b405bd23baf8121caa294 to your computer and use it in GitHub Desktop.
Save yggi/cbb25f2d570b405bd23baf8121caa294 to your computer and use it in GitHub Desktop.
Apt-get can't connect to 'security.ubuntu.com'

Apt-get can't connect to 'security.ubuntu.com'

https://zach-adams.com/2015/01/apt-get-cant-connect-to-security-ubuntu-fix/

Ran into this issue today where on a newly made Linode Ubunu 14.04 LTS server I ran

apt-get update

The command started alright however eventually it would reach a point where it got stuck at

Connecting to security.ubuntu.com (2001:67c:1562::16)

And wouldn’t continue no matter what. Turns out this is an issue where connecting over IPv6 on some servers causes them to get stuck at this point. The fix is really simple.

Open /etc/gai.conf

Uncomment the following line:

#
# For sites which prefer IPv4 connections change the last line to
#
precedence ::ffff:0:0/96 100

This will allow you to still use IPv6 but sets IPv4 as the precedence so that apt-get won’t get stuck.

@nilsnolde
Copy link

Thx, worked like a charm!

@khal3d
Copy link

khal3d commented Jun 21, 2018

Didn't work for me :(

@Invalid-Handle
Copy link

Invalid-Handle commented Aug 16, 2022

In my case this was being blocked by my firewall IDS/IPS which is set to block traffic that generates an alert.
ET POLICY GNU/Linux APT User-Agent Outbound likely related to package management
I disabled that rule, removed the above alert/IPs from the block list, and added the above alert to the suppress list.
Disable the rule on both LAN and WAN interfaces if this situation applies to you.

I'm able to connect to update servers now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment