Skip to content

How to prefer IPv4 in Linux?

  • by

In Linux with IPv6 and IPv4 (dualstack), IPv6 address have preference.
This can be easily changed in file /etc/gai.confadd lines

# /etc/gai.conf

precedence ::ffff:0:0/96  100
precedence ::/0           40

How this work?

The number indicates priority (higher = higher priority). ::ffff:0:0/96 represents IPv4 addresses mapped into IPv6.
This affects all applications that use standard getaddrinfo() calls.

Test by command

getent ahosts google.com
# IPv4 should appear first.

Leave a Reply

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