Tell me more ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

The ISP I work at is setting up an internal IPv6 network in preparation for eventually connecting to the IPv6 internet. As a result, several of the servers in this network now try to connect to security.debian.org via its IPv6 address by default when running apt-get update, and that results in having to wait for a lengthy timeout whenever I'm downloading updates of any sort.

Is there a way to tell apt to either prefer IPv4 or ignore IPv6 altogether?

share|improve this question
Shouldn't that return immediately with a routing failure? – pjc50 Mar 23 '11 at 11:46
1  
No, it's entirely possible that their internal network has routing between multiple subnets (and hosts have an IPv6 default gateway) but no IPv6 connectivity to the outside world. – Andrew Medico Mar 23 '11 at 13:51
2  
There's probably a way to set up /etc/gai.conf so that security.debian.org's A record are returned before the AAA record, but I don't know precisely what to put in that file. – Gilles Mar 24 '11 at 0:10

5 Answers

up vote 22 down vote accepted

As Gilles says, use gai.conf

Say we have two hosts www.he.net and www.ripe.net

$ host www.he.net
www.he.net is an alias for he.net.
he.net has address 216.218.186.2
he.net has IPv6 address 2001:470:0:76::2


$ host www.ripe.net
www.ripe.net has address 193.0.6.139
www.ripe.net has IPv6 address 2001:67c:2e8:22::c100:68b

Case 1: Prefer IPV4

Append the following to /etc/gai.conf

precedence ::ffff:0:0/96  100

then we have:

$ telnet www.ripe.net 81
Trying 193.0.6.139...
^C
$ telnet www.he.net 81
Trying 216.218.186.2...

Case 2: Prefer IPV6 for specific hosts

If we append

precedence 2001:470::/32 100

then we have

$ telnet www.ripe.net 81
Trying 193.0.6.139...
^C
$ telnet www.he.net 81
Trying 2001:470:0:76::2...
^C

So we seem to prefer that network for ipv6 and ipv4 everywhere else.

Case 3: Prefer ipv4 for specific hosts

Wondering if we invert the mask the reverse will be true.


See also:

share|improve this answer
Perhaps summarize content in case the above links disappear? – Faheem Mitha May 16 '11 at 15:04
So, what's the syntax to disable IPv6 for a particular name, or at least for a particular address (range)? If you add that to your post, it'll be the best answer here. – Gilles May 16 '11 at 16:16
Thanks, this worked. – Shadur May 17 '11 at 17:41

You could work around this by setting up a DNS proxy server that dropped ip6 responses.

share|improve this answer
Won't your local resolver still try to get the AAAA record? And time out? – Mikel May 15 '12 at 14:32

How about adding a line in /etc/hosts overriding the relevant addresses? e.g.,

130.89.149.226  ftp.debian.org      
195.20.242.89   security.debian.org 
share|improve this answer
5  
I'll save this solution for last if there turns out to be absolutely no other way; I really don't like cluttering /etc/hosts with IP addresses I don't own myself. – Shadur Mar 23 '11 at 11:34
@Shadur Yes, I can totally see your point :) – badp Mar 23 '11 at 12:49
Note: these need to be flipped, so it is IP then hostname – Mike Toews May 14 '12 at 13:42

You could setup apt-cacher-ng on a spare machine to act as a proxy/cache for all of your hosts. You can force the configuration to only use specific hosts or use the /etc/hosts trick suggested by @badp on that one machine.

apt-get install apt-cacher-ng

Once you have apt-cache-ng setup you just need to drop the following line (with IP address/hostname altered to point at your cacher machine) in /etc/apt/apt.conf.d/90httpproxy

Acquire::http { Proxy "http://[192.168.1.254]:3142"; };

I use that setup to reduce bandwidth usage but it should workaround your problem. Unfortunately I'm not aware of a way to directly disable ipv6 lookups for apt-get itself.

share|improve this answer
Still not a perfect solution, but as good as it's likely going to get. Thanks. – Shadur Mar 24 '11 at 10:49

I have found a much better way to do this. Open up your sources.list file and note down the hostnames of the repos. Get their IPv4 addresses, then edit sources.list with the IPv4 addresses rather than the hostnames. Apt-get should now contact the repositories over the IPv4 addresses you specified, bypassing IPv6.

There is the disadvantage that repos usually have some sort of load balancing and/or IP geolocation set up, which this method of course bypasses. However, it shouldn't matter if only a few people are doing it. If you do find one mirror is slow, try getting another repo IP address (for instance, by using an online ping service) and use that.

share|improve this answer
That's a really bad solution, actually, for the reasons you already describe. – Shadur Apr 18 at 4:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.