I'm working on a network client program that connects to public servers, specified by the user. If the user gives me a hostname to connect to that has both IPv4 and IPv6 addresses (commonly, a DNS name with both A
and AAAA
records), I'm not sure how I should decide which address I should connect to.
The problem is that it's quite common for machines to support both IPv4 and IPv6, but only to have global connectivity over IPv4. The most common case of this is when only IPv6 link-local addresses are configured. At the moment the best alternatives I can come up with are:
The problem I can see with option 1 is that the connection might not fail straight away - it might take quite a while to time out.
The host must have DNS or hosts file entries for both IPv4 and IPv6 addresses. The host must also be configured to resolve host names and IP addresses from the DNS or from the hosts file. The network path between the two components must be enabled for IPv6 traffic.
When possible, it is better to keep both IPv4 and IPv6 addresses enabled. For example, using only IPv6 can cause some accessibility issues, as only about one third of the internet supports IPv6 addresses. Likewise, disabling IPv6 can cause certain problems, especially if your router is already using an IPv6 address.
The primary function of IPv6 is to allow for more unique TCP/IP address identifiers to be created, now that we've run out of the 4.3 billion created with IPv4. This is one of the main reasons why IPv6 is such an important innovation for the Internet of Things (IoT).
Best answer: IPv6 can potentially add support for more devices, better security, and more efficient connections. While some older software may not work as expected, most of your network should work fine with IPv6 enabled.
Please do try IPv6. In the significant majority of installations, trying to create an IPv6 connection will fail right away if it can't succeed for some reason:
There are of course cases where things can break, e.g. if a global (or tunnel) address is configured, and something falsely filters out ICMPv6 error messages. You shouldn't worry about this case - it may be just as well that IPv4 connectivity is somehow broken.
Of course, it's debatable whether you really need to try the IPv6 addresses first - you might just as well try them second. In general, you should try addresses in the order in which they are returned from getaddrinfo. Today, systems support configuration options that let administators decide in what order addresses should be returned from getaddrinfo.
Subsequent to the question being asked the IETF has proposed an answer to this question with RFC6555, a.k.a. Happy Eyeballs.
The pertinent point being the client and server may both have IPv4 and IPv6 but a hop in between may not so it is impossible to reliably predict which path will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With