How to prefer IPv4 over IPv6 in Ubuntu and CentOS



You can change this by editing the precedence blocks in /etc/gai.conf.  Locate this line:

#precedence ::ffff:0:0/96  100

And un-comment it to look like:


precedence ::ffff:0:0/96  100



You'll need to modify the /etc/gai.conf to look like:


label       ::1/128        0
label       ::/0           1
label       2002::/16      2
label       ::/96          3
label       ::ffff:0:0/96  4
precedence  ::1/128        50
precedence  ::/0           40
precedence  2002::/16      30
precedence  ::/96          20
precedence  ::ffff:0:0/96  100


That should be it.  That should set up the precedence for you so that your server(s) will use IPv4 over IPv6 without disabling IPv6 on the server. :)