Forcing IPv4 with APT

So as you may or may not know, I am an adopter of IPv6 and I setup IPv6 on all my servers and desktop machines. Usually I forget it's even enabled until I see DNS resolution in the shell or go to a site that reports my IP address back to me.

Today I was installing i2c and noticed that I could not download their key with SSL over IPv6 (they should fix this).

bman@lightmyfire:~$ wget  
--2015-01-12 02:53:22--
Resolving ( 2a02:180:1:1:2456:6542:1101:1010,  
Connecting to (|2a02:180:1:1:2456:6542:1101:1010|:443...  

After a few minutes, I ctrl-c'ed it and just happened to remember wget suppports -4.

bman@lightmyfire:~$ wget -4  
--2015-01-12 02:55:06--
Resolving (  
Connecting to (||:443... connected.  
HTTP request sent, awaiting response... 200 OK  
Length: 9127 (8.9K) [text/plain]  
Saving to: ‘i2p-debian-repo.key.asc’

100%[======================================>] 9,127       --.-K/s   in 0.004s  

2015-01-12 02:55:07 (2.02 MB/s) - ‘i2p-debian-repo.key.asc’ saved [9127/9127]  

So that was easy enough, then when I tried to run the old apt-get update and it hangs just like the wget did at this line:

100% [Connecting to (2607:f8b0:4000:80b::200e)]  

Just sitting there, no timeout that I can tell (I get impatient and ctrl-c before it occurs either way).
I would blame Google cloud for this, but when I checked where resolved to, it was to an Amazon AWS CloudFront IP address.

Thankfully, in an update to apt in the last couple of years, they added the ability to force to IPv4 as most other CLI programs can. Here is how to do it:

apt-get -o Acquire::ForceIPv4=true update  

Which results in:

Fetched 214 kB in 9s (22.8 kB/s)  
Reading package lists... Done  

Yay, the apt-get update was successful. Now if you want to make the setting persistent for all APT calls, you will need to create a file called /etc/apt/apt.conf.d/99force-ipv4 and make the contents:

Acquire::ForceIPv4 "true";  

This will always force apt to use IPv4 at all times which I do not recommend, however it could help with handling extended routing issues.

As this does not seem to be in a current man page, here is the closest thing to docs I could find.

bmanio forum