Hosts File Not Working? Check Your IPv6 Loopback (especially with Cloudflare)
5th November 2025
Backstory
Whilst migrating sites from one hosting environment to another, I was making changes to my hosts file to check all was well. It appeared that when I was checking sites that were behind Cloudflare, I wasn’t able to see the new hosting environment after setting the new IP in my hosts file. Even CURL wouldn’t see the new host unless I forced the domain to resolve on a different IP - which didn’t help actually seeing the website.
Spending much time trying to troubleshoot this (with the help of Gemini I might add), I eventually came across the command dscacheutil -q host -a name www.example.com.
As I understand it, the above command returns the domain and the IP addresses’ that are used to reach the domain:
name: a1422.dscr.akamai.net
alias: www.example.com www.example.com-v4.edgesuite.net
ipv6_address: 2a02:26f0:1780:1a::214:c53
ipv6_address: 2a02:26f0:1780:1a::214:c5c
name: a1422.dscr.akamai.net
alias: www.example.com www.example.com-v4.edgesuite.net
ip_address: 104.77.160.87
ip_address: 104.77.160.71
After feeding this result back into Gemini, it was determined that the browswer (at least) was connecting to the site via IPv6 which, oddly, I hadn’t thought about despite recently having problems with Cloudflare rules not working for my IP - again, because I was connecting via IPv6.
Updating the hosts file to create a IPv6 loopback (which I think then forces the IPv4 address to resolve), this instantly fixed my issue. I was able to view the new host on the ‘live’ domain.
Here’s the hosts file for creating the loopback:
# Set the IP you want to use instead for the domains in the usual format.
1.2.3.4 example.com www.example.com
# Create the loopback to the same domains
::1 example.com www.example.com
Sorted