Prefer IPv4 over IPv6

I try to use IPv6 where it’s available but it’s sometimes so hard… It happen quite often that I can’t download packages from repos because they weren’t configured on IPv6 vhosts even when host is available via IPv6 address. For APT you may use this trick to force IPv4 connections only:

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

If you need more than that, then gai.conf will allow you to filter where you will be connecting via IPv4 and where via IPv6 – in example bellow you will prefer IPv4 whenever it’s available:

echo 'precedence ::ffff:0:0/96  100' >> /etc/gai.conf

Leave a Reply

Your email address will not be published. Required fields are marked *