HowTo invite applications to use IPv4 or IPv6

Introduction

IPv6 is not really news, but unfortunately there may still be situations where an application tries to make a particular connection using IPv6 although only IPv4 is set up usuable.

The following config snippets should help to enforce a particular IP variant in dual-stack setups or situations.

IPv4/IPv6 priorities of operating systems

Be aware that applications may ignore the following settings, or only respect them when the application is restarted.

Linux

To have most applications use IPv4 connections, uncomment the following line in /etc/gai.conf:

precedence ::ffff:0:0/96  100

MacOS, Windows

TBD.

IPv4/IPv6 priorities of applications

ApplicationCommand line optionsConfig file optionsConfig file names, Remarks
apt-*
-o Acquire::ForceIPv4=true
-o Acquire::ForceIPv6=true

Acquire::ForceIPv4 "true";

Acquire::ForceIPv6 "true"; 

Suggestion: /etc/apt/apt.conf.d/99force-ipv4

apt ignores gai.conf

Java JVMs

-Djava.net.preferIPv4Stack=[true|false]

-Djava.net.preferIPv6Addresses=[true|false]

java.net.preferIPv4Stack = [ true | false ]

java.net.preferIPv6Addresses = [ true | false ]

java.net.preferIPv*Stack are actually JVM system properties

OpenSSH

[ -4 | -6 ]

AddressFamily any | inet | inet

/etc/ssh/ssh*_config, ~/.ssh/config
Postfix inet_protocols = all | inet4 | inet6/etc/postfix/main.cf

Probably obsolete, from 2009: Java in Ubuntu/Debian: Sometimes these JVM parameters are not enough. As documented in Ubuntu bug 486215 and Eclipse bug 298515 it may also be required to set net.ipv6.bindv6only to 0 using /sbin/sysctl net.ipv6.bindv6only=0 respectively editing /etc/sysctl.d/bindv6only.conf

TBC ...