Skip to content

How to change IPv4 priority in dual stack Linux

Overview

When a Linux server has both IPv4 and IPv6 addresses (dual stack), the system decides which protocol to prioritize for external connections based on DNS resolution and system configuration rules. By default, Linux prefers to use IPv6 for external access as long as the target service supports IPv6.

Default Priority Mechanism

When accessing an external service using a domain name, Linux queries both A records (IPv4) and AAAA records (IPv6).

If the target service provides an IPv6 address, the system will typically choose IPv6 for the connection, reflecting modern best practices and IETF recommendations.

How to Adjust Priority

#
#    For sites which prefer IPv4 connections change the last line to
#
#precedence ::ffff:0:0/96  100

The /etc/gai.conf file can be modified to change the preference. For example, uncommenting or adding the following increases the priority for IPv4 over IPv6

precedence ::ffff:0:0/96 100

Verification

curl ifconfig.me

Reference

  • https://u.sb/debian-prefer-ipv4/
  • https://blog.acesheep.com/p/linux-dualstack-ipv4-preferred/
Feedback