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 https://geti2p.net/_static/i2p-debian-repo.key.asc --2015-01-12 02:53:22-- https://geti2p.net/_static/i2p-debian-repo.key.asc Resolving geti2p.net (geti2p.net)... 2a02:180:1:1:2456:6542:1101:1010, 220.127.116.11 Connecting to geti2p.net (geti2p.net)|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
bman@lightmyfire:~$ wget -4 https://geti2p.net/_static/i2p-debian-repo.key.asc --2015-01-12 02:55:06-- https://geti2p.net/_static/i2p-debian-repo.key.asc Resolving geti2p.net (geti2p.net)... 18.104.22.168 Connecting to geti2p.net (geti2p.net)|22.214.171.124|: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 dl.google.com (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 dl.google.com 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 bman@lightmyfire:~$
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:
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.