2

I have CentOS 7 running on an AWS machine. I recently enabled IPv6, and everything was working fine – except for the fact that PHP connection requests (also curl from command line) always prefer to use IPv6 instead of IPv4. This causes some issues with websites that don't really support it such as send notifications to Apple, Android, and everything worked well as IPv4.

How can I make all my outgoing requests use IPv4 instead of IPv6? I also don't want to disable incoming IPv6, as some of my clients use IPv6 only.

1 Answer 1

5

Most programs that are capable of using IPv6 will use whichever address (IPv4 or IPv6) the system's DNS resolver library reports as the most preferred one for the host.

The preference of the resolver library can adjusted using the /etc/gai.conf file.

The precedence rules are specified in this part of the file:

# precedence  <mask>   <value>
#    Add another rule to the RFC 3484 precedence table.  See section 2.1
#    and 10.3 in RFC 3484.  The default is:
#
#precedence  ::1/128       50
#precedence  ::/0          40
#precedence  2002::/16     30
#precedence ::/96          20
#precedence ::ffff:0:0/96  10
#
#    For sites which prefer IPv4 connections change the last line to
#
#precedence ::ffff:0:0/96  100

The built-in defaults are listed as commented values, but if you specify your own settings, the defaults won't be used at all. So add this to the end of the file:

# To prefer IPv4 over everything else
precedence ::ffff:0:0/96  100
precedence  ::1/128       50
precedence  ::/0          40
precedence  2002::/16     30
precedence ::/96          20

Note that it is not possible to answer in IPv4 to an incoming connection that arrives using IPv6, or vice versa: by the rules of the IP and TCP protocols, any connection attempt must be answered using the protocol the request was made with.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.