brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: Acquire::ForceIPv4 fixes apt update when it hangs on a broken IPv6 route

Apt
~/tips/tip-apt-acquire-forceipv4

sudo apt -o Acquire::ForceIPv4=true update

Makes apt download over IPv4 only when IPv6 connections stall.

If apt update sits at Connecting to archive.ubuntu.com for ages, the machine may think it has working IPv6 while the route behind it is broken. apt tries IPv6 first and waits.

Test it for one run first:

sudo apt -o Acquire::ForceIPv4=true update

If that is fast while a normal apt update hangs, IPv6 is the problem. To make it stick, put the setting in its own file:

echo 'Acquire::ForceIPv4 "true";' | sudo tee /etc/apt/apt.conf.d/99force-ipv4

From then on apt downloads over IPv4 only. There’s also Acquire::ForceIPv6 for the opposite case, an IPv6-only network where IPv4 attempts time out.

I see this as a workaround, not a fix. The real problem is the IPv6 setup, and other programs on the same machine may have the same delays without telling you. A quick curl -6 -I https://archive.ubuntu.com shows whether IPv6 works at all. If it doesn’t and you don’t need it, fix it at the network or router level.

Remember the file is there. Months later, when IPv6 does work or you move the machine to an IPv6-only network, a forgotten 99force-ipv4 can be the reason apt fails, and apt-config dump | grep ForceIPv will show it.

Further reading: apt.conf(5) manual page

More Apt tips sudo apt-mark minimize-manual apt list '~c' grep -E ' (install|upgrade|remove) ' /var/log/dpkg.log | tail -o Dpkg::Options::="–force-confold" upgrade sudo apt-get -d -y full-upgrade All Apt tips (42) All topics

Link