Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I currently manage two servers on Linode. The first "server-a" is running 12.04, the second "server-b" is a fresh install of 14.04.

A while ago I had some trouble with spf records on server-a and came to the realization that I needed to explicitly add (or create an A record for) the ipv6 address since the postfix service was using ipv6 to connect to gmail. This was surprising to me since I just assumed it would be using ipv4 by default. After a bit more followup I discovered that nearly all services were using ipv6 in some cases but not others.

For instance, if postfix delivers mail, or if I telnet or ssh to another host on Linode my ipv6 address shows up the log. On the other hand if I connect to my local server here at home or to one on Digital Ocean's network, ipv4 is used.

Can anyone explain when and how it is determined that ipv4 or ipv6 should be used when establishing a connection? Does it vary from service to service or is this part of a central configuration?

share|improve this question
Generally, IPv6 is the default and is used wherever possible. IPv4 is used only as a fallback. –  Michael Hampton Jul 6 at 20:32

1 Answer 1

up vote 3 down vote accepted

Services are usually accessed using a hostname, which usually means that DNS is used to look up the IP address(es) linked to that hostname. For IPv4 there will be A records, and for IPv6 there will be AAAA records. All those addresses are supposed to offer the same service, independent of the protocol used.

So if you send email to Gmail your mailserver will look up the MX (mail exchange) records for gmail.com. From my point of view those are:

gmail.com.  MX  5   gmail-smtp-in.l.google.com.
gmail.com.  MX  10  alt1.gmail-smtp-in.l.google.com.
gmail.com.  MX  20  alt2.gmail-smtp-in.l.google.com.
gmail.com.  MX  30  alt3.gmail-smtp-in.l.google.com.
gmail.com.  MX  40  alt4.gmail-smtp-in.l.google.com.

The highest priority MX is gmail-smtp-in.l.google.com, so let's look at its addresses:

gmail-smtp-in.l.google.com.  A
gmail-smtp-in.l.google.com.  A
gmail-smtp-in.l.google.com.  AAAA  2a00:1450:4013:c01::1b

So now your mailserver has three addresses it can use. DNS doesn't tell you which one is preferred. That choice is up to your local software. There is a whole RFC about the algorithm to use (RFC 6724) but it usually boils down to: use IPv6 when available, otherwise IPv4.

Postfix (≥ 2.9) will, unless explicitly configured otherwise, use both IPv4 and IPv6 when available. It will first try IPv6, and if it can't connect using IPv6 it will connect using IPv4.

Web browsers work in a different way these days since the invention of Happy Eyeballs / RFC 6555. Because connectivity problems on IPv6 would cause annoying or even unworkable timeouts a browser will try to use IPv6, but if it hasn't heard anything after ±200ms it will try to connect using IPv4 in parallel. The first connection to succeed will be used.

And of course: if the service you are using doesn't advertise any IPv6 addresses in DNS then only IPv4 will be used. And vice versa.

share|improve this answer
thanks. that's pretty much crystal clear. so bascially, as i understand it, the linode to linode and linode to gmail connections use ipv6 since they both have the capacity, but likely none of the others do so reverts to ipv4. –  billynoah Jul 6 at 23:17
Yes. Although they might have the capacity but choose not to advertise it in DNS for some reason. –  Sander Steffann Jul 7 at 8:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.