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 xenial-updates InRelease [94.5 kB]
0% [Connecting to (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 xenial InRelease
Reading package lists... Done


Ubuntu bug #1412943: (2001:67c:1562::XXX) not reachable

Adams 2015: Apt-get can’t connect to ‘’

Ubuntuforums: 0% [Connecting to (2001:67c:1562::14)] – Install not happening


Tested on Ubuntu 16.04 LTS x86_64.

Posted in Uncategorized | Tagged , , , , , , , , , | Comments Off on Prefer IPv4 on Ubuntu 16.04 LTS xenial – /etc/gai.conf

Comments are closed.