I recently encountered some weirdness with DNS in OSX that I thought I’d share, in case it came in helpful for anyone.
The scenario was that a client’s website displayed fine on my laptop with the plain variant of the email (e.g. http://domain.com), but the www variant was pointing to the server’s default page. Pinging the server from Terminal in my Mac yielded the same IP address for both, so all looked good.
Initially I thought that it was a server configuration issue, so checked all the settings, but there was nothing obvious.
I then checked the DNS records for the domain thinking that perhaps we didn’t change both variants when we went live (the site was done in a hurry and went live late at night), but everything looked fine.
Then, clutching at straws, I added a test file to the server’s default site to make sure I was really looking in the right place, and realised that I was looking at my Apache server, not the Windows one I expected.
At this point I realised that something odd must be going on with DNS, so went to the server in Remote Desktop and checked in the browser there. The www variant worked. Then I checked on my phone and it also worked, so something odd was definitely going on with my Mac.
At this point it occurred to me to open the hosts file, and to my surprise it seemed I’d added an entry for the www variant of the domain for the previous version of the client’s website (which was WordPress, hence the Apache server) literally years ago (in fact, OSX must have migrated the hosts file from my old laptop).
So the morals of the story are:
- Never forget that OSX is too clever by half
- Don’t trust the IP address yielded by ping in Terminal on a Mac, try a third-party service to be sure.