Set DigitalOcean Debian/Ubuntu server to default to IPv4 for DNS resolution

Written by:
Posted in: ,
Published: October 19, 2016

Recently while trying to get a Google Apps (Gsuite) SMTP relay working on a site running WordPress we ran into an issue with PHPMailer where DNS resolution was failing because the server was defaulting to IPv6. In case anyone else runs into this, the solution is simple:

1. Open the getaddrinfo() config file in your favorite editor:

nano /etc/gai.conf

2. Uncomment this line:
precedence ::ffff:0:0/96 100

3. Save and exit.

The reason this is needed is because DigitalOcean is currently is blocking outgoing IPv6 SMTP traffic.