Prefer IPv4 on Ubuntu 16.04 LTS xenial – /etc/gai.conf

New Ubuntu 16.04 LTS Xenial prefers IPv6 connections. In some networks, this breaks software updates.

You can easily fix this by making Ubuntu prefer IPv4 connections over IPv6.

The Bug

Updating the list of available packages fails in some network conditions. Not getting security updates can cause security issues.

$ sudo apt-get update
Get:2 http://mirror.example.com/ubuntu xenial-updates InRelease [94.5 kB]
...
0% [Connecting to security.ubuntu.com (2001:67c:1562::16)]^C

The Fix

Tell computer to prefer old style IPv4 connections over the new IPv6.

$ sudoedit /etc/gai.conf

Uncomment the line

precedence ::ffff:0:0/96  100

It works

Now sudo apt-get update runs normally.

$ sudo apt-get update
Hit:1 http://mirror.example.com/ubuntu xenial InRelease
...
Reading package lists... Done

Sources

Ubuntu bug #1412943: security.ubuntu.com (2001:67c:1562::XXX) not reachable

Adams 2015: Apt-get can’t connect to ‘security.ubuntu.com’

Ubuntuforums: 0% [Connecting to us.archive.ubuntu.com (2001:67c:1562::14)] – Install not happening

Adminstrivia

Tested on Ubuntu 16.04 LTS x86_64.

Posted in Uncategorized | Tagged , , , , , , , , , | Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Picks

  • Boxing Clock for AndroidOcton8 Diving T-ShirtsShaking Tower Panda Android GameLearn Chinese with Android
  • Student projects