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, 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).


    • LoneSwimmer on June 26, 2014 at 7:51 PM
    • Reply

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

    • Attila Fulop on January 8, 2016 at 2:25 PM
    • Reply

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

    • HusseinOsama on January 26, 2016 at 11:40 PM
    • Reply

    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

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Read previous post:
Πλαστογραφημένες δικτυακές αιτήσεις

Το Cross-Site Request Forgery δεν αποτελεί ιδιαίτερα γνωστή μέθοδο επίθεσης, αλλά να είσαστε σίγουροι ότι είναι αρκετά επικίνδυνη. Σε αυτό...