As Gilles says, use gai.conf . Notes:

This works at a much lower level (DNS and IP networking) than APT, so it will change how all your applications network--at least, all that use getaddrinfo . Before editing your gai.conf , you should back it up, and also read it (don't worry, it's short). The edits below are probably already mentioned in your current file; if the current file indicates something different from what's mentioned below, you should probably prefer what's in your current file.

But if this is what you want (which it probably is), let's proceed. 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 for all hosts

Append to /etc/gai.conf the following line:

precedence ::ffff:0:0/96 100

After saving the edited file (no need to restart), you should see networking apps (e.g., telnet ) using IPV4: e.g.,

$ 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 want to prefer IPV6 only for www.he.net or its network, we can append a mask/prefix for all, or just some part, of its IPV6 address to /etc/gai.conf . E.g., the following line:

precedence 2001:470::/32 100

(after saving the edited file) produces

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

Case 3: prefer IPV4 for specific hosts

If we invert the mask will the reverse be true? According to @GrueMaster, appending

precedence 2001:470::/96 100

worked for him after disabling IPV6 for security.ubuntu.com (otherwise it stalls forever).

See also: