«

»

Jan 21 2014

Make apt-get use IPv4 instead of IPv6

It seems that Ubuntu/Debian (or perhaps other distros as well) prefer IPv6 DNS records instead of IPv4 when applicable and some times this results in loss of connectivity or similar problems.

I ran into this issue today while trying to update an old VPS with apt-get/aptitude. Specifically, security.ubuntu.com was being resolved in an unreachable IPv6 address and I had to wait some minutes for timeout every time.

Fortunately, there is an easy fix for this; you just have to edit the file located at: /etc/gai.conf which is the configuration for getaddrinfo(). There you have to uncomment line ~54 which reads: “precedence ::ffff:0:0/96  100”, and you are all set! (assuming that every other option is commented out by default as in my case).

3 comments

  1. LoneSwimmer

    Thanks very much. When will the change take effect, next IP lease or would it be easier to just restart?

  2. Attila Fulop

    It works, thanks a lot. What does it actually do?

  3. HusseinOsama

    The correct way to do it is:

    Create a file in /etc/apt/apt.conf.d/99force-ipv4 or something with content:

    Acquire::ForceIPv4 “true”;

Leave a Reply

More in General News
BlackHat USA 2012 – Owning Bad Guys (and Mafia) with Javascript Botnets
Christiaan008: The Honey project and CIC News Engine
Disable mod_security with htaccess
Honeypot Workshop @ BruCON 2013
How to resize an EC2 root partition
Close