How web browser determines when to use IPv4 or IPv6 to connect to the destination?
I saw couple of related posts on this topic: How do client applications know to use IPv4 or IPv6? and How to know if your browser is connected to the Ipv4 or Ipv6 address of a website?
The first post is couple years old so I am not sure if it is still relevant and the 2nd one didn't answer my question.
Reason I ask is I installed pi hole to help blocking ads. I setup my router to use pi-hole as my IPv4 DNS server, however I still see advertisements when browsing site like CNN. I then realized that my ISP provider (Comcast) provided two IP addresses, one IPv4 and one IPv6 and my router also supports IPv6.
When I manually disable IPv6 on my network card then advertisements stop showing up when I browse CNN website. Therefore I concluded that I was using IPv6 to connect to the CNN website. My question is when a web browser decides to use IPv4 or IPv6 to connect to the destination? Does is simply try to use IPv6 first and if succeeded then use it, otherwise fall back to IPv4?
A side note, apparently Arris SBG6700-AC modem/router only allow you to configure IPv4 DNS server but not IPv6 DNS server. To specify your own IPv6 DNS server, I must set that up from the computer itself.
Solution 1:
First: How you resolve a hostname has nothing to do with what address you can resolve it to. DNS servers are perfectly capable of returning IPv6 AAAA records when asked via IPv4, and vice versa.
As for how a browser chooses which address to try: The first post you linked to is still relevant, the only things that changed are minor priority adjustments.
-
Most modern browsers use the Happy Eyeballs algorithm; they try all addresses at once and stick with the one which replies fastest. This is implemented entirely within the app and cannot be influenced by the OS. (Note that the algorithm is sometimes tweaked to give a head start to IPv6 or IPv4 in case they both give similar results.)
-
Older browsers and many other programs try all addresses one by one, sorted according to a default address selection algorithm, which usually prefers native IPv6 over native IPv4 over automatic v6 tunnels. This ordering is usually implemented in the OS (e.g. gai.conf), and programs don't sort addresses manually.
Solution 2:
You cannot directly control how the web browser determines whether it uses IPv6 or IPv4.
That is all handled by the IP stack in the computer.
As for the ads, I suggest you look at alternative ad blockers. I don't believe the v4 vs v6 issue is responsible for the results you are seeing.
Hint for Windows: Adblock does a good job. Just don't use Adblock Plus because it is a memory hog as it loads in tables of "allowable" ads.
Meanwhile, from your question, I have a suggestion: Set all your routers to disable IPv6 until such a time as it may be required.
Then do the same for all your computers: For each interface, uncheck the IPv6 support (Windows), or set it to disabled or automatic (Linux) and let the routers handle the rest.
One day IPv6 will become necessary, but that will be largely an issue affecting ISPs. (I use Cox Cable) To push it all the way down to the user level, they would have to replace our combined modem/router box at that time. Or, they will require all their users to do their own router reconfigurations. They will suffer losses if they do either of those things, especially if the add any extra charges for the change or help-line support. In the end I predict that Cox will figure out a way to prevent such a large amount of work. They are a business and they must realize that if there are any more extra charges or possible user-induced configuration errors resulting in downtime then they will lose customers.
So for now, there is no need for IPv6 at all, at the user level.
All your systems behind your NAT router will likely be able to continue to use v4 for the forseeable future. v6 will only be necessary on the larger net.