Disable AAAA lookups in libcurl

a-recorddomain-name-systemresolve

We have a step during in of our large map reduce that does DNS resolutions. The application itself uses the c-ares library as well as libcurl.

I notice that with each resolution, there is first an AAAA attempt, then immediately an A resolution. This is seen clearly with TCPdump both on our named server as well as on the host.

Here's a sample of traffic to S3

$ tcpdump dst port 53
20:28:35.259552 IP x.x.x.x.55271 > ec2-xx.amazonaws.com.domain: 21815+ AAAA? s3.amazonaws.com. (34)
20:28:35.261526 IP x.x.x.x.56058 > ec2-xx.amazonaws.com.domain: 21823+ A? s3.amazonaws.com. (34)

And it repeats for each resolution. Since we do more than 70 million resolutions during this process, it makes sense to want to cut out 50% of this as waste.

How can I disable IPv6 lookups in Ubuntu?

I've tried changing the precedence in /etc/gai.conf to:

precedence ::ffff:0:0/96 45

Yet I am still seeing ubuntu first try IPv6 resolutions. Any help would be greatly appreciated

Edit:

My /etc/resolv.conf is simple with just a nameserver set:

cat /etc/resolv.conf 
nameserver x.x.x.x

Best Answer

IPv6, not IPv4, is the forward-looking version of IP, you know... IPv6 is sorry to see you go :-( But you can disable it.

If you are using libcURL then all you have to do is this:

curl_easy_setopt(easy_handle, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);

However, are you worried about the time these extra AAAA requests take, or the extra network traffic? I would hope that the A and AAAA are done in parallel so you shouldn't need to worry about a delay.