Need to Verify DNS Locally Using Hosts on OSX?

OSX Mac Terminal

One of my clients relocated their website to a bulk hosting account. They updated their domain's DNS settings for the A and CNAME records but were having a difficult time determining whether or not the site was resolving with the new hosting account (new IP Address).

There are a few things to keep in mind when troubleshooting DNS. Understanding how DNS works, understanding how your Domain Registrar works, and then understanding how your host manages their domain entry.

How DNS Works

When you type a domain into a browser:

  1. The domain is looked up in an Internet name server to locate where the request should be sent to.
  2. In the case of a web domain request (http), a name server will returns the IP address to your computer.
  3. Your computer then stores this locally, known as your DNS Cache.
  4. The request is sent to the host, which routes the request internally and presents your site.

How Your Domain Registrar Works

A note on this… not every domain registrar actually manages your DNS. I have one client, for example, that registers their domains through Yahoo! Yahoo! doesn't actually manage the domain despite it appearing so in their administration. They're just a reseller for Tucows. As a result, when you make a change to your DNS settings in Yahoo!, it can take hours before those changes are actually updated in the real domain registrar.

When your DNS settings do get updated, they are then propogated across an array of servers across the Internet. Most of the time, this literally just takes a few seconds to happen. This is one reason why people will pay for managed DNS. Managed DNS companies typically have both redundancy and are incredibly fast… often faster than your domain registrar.

Once the Internet servers are updated, the next time your system makes the DNS request, the IP address where your site is hosted is returned. NOTE: Keep in mind that I said the next time your system makes the request. If you previously requested that domain, the Internet could be up to date but your local system may be resolving an old IP address based on your DNS Cache.

How Your Host DNS Works

The IP address that's returned and cached by your local system isn't typically unique to a single website. A host may have dozens or even hundreds of websites hosted on a single IP Address (typically a server or virtual server). So, when your domain is requested from the IP Address, your host forwards your request to the specific folder location within the server and presents your page.

How to Troubleshoot DNS

Because there are three systems here, there are also three systems to troubleshoot! First, you'll want to just check your local system to see where the IP Address is pointing to in your system:

OSX Terminal Ping

This is done easily by opening a Terminal window and typing:


Or you can actually do a specific name server lookup:


Terminal nslookup

If you've updated the DNS settings in your domain registrar, then you'll want to ensure your DNS cache is cleared and you'll want to make the request again. To clear your DNS cache in OSX:

sudo dnscacheutil -flushcache

Terminal Flush DNS Cache

You can retry the ping or nslookup to see if the domain resolves to a new IP address at this point.

The next step would be to see if the Internets DNS servers have been updated. Keep DNSstuff handy for this, you can get a full DNSreport through their platform that's really good. Flywheel has a great DNS Checker in its platform where they'll go query Google, OpenDNS, Fortalnet, and Probe Networks to see if your settings have propagated properly around the web.

If you're seeing the IP address properly displayed across the web and your site is still not showing up, you can also bypass the Internet's servers and tell your system just to send the request directly to the IP Address. You can accomplish this by updating your hosts file and flushing your DNS. To do this, open Terminal and type:

sudo nano /etc/hosts

Terminal Sudo Nano Hosts

Enter your system password and press enter. That will bring up the file directly in Terminal for editing. Move your cursor using your arrows and add a new line with the IP address followed by the domain name.

Terminal Hosts Save File

To save the file, press control-o on your keyboard then return to accept the filename. Exit the editor by pressing control-x, which will return you to the command line. Don't forget to flush your cache. If the site doesn't come up okay, it may be a problem local to your host and you should contact them and let them know.

Last note… don't forget to return your hosts file to its original version. You don't want to leave an entry in there that you want updating automatically!

By following these steps, I was able to verify that my the DNS entries in the registrar were up to date, the DNS entries on the Internet were up to date, my Mac's DNS cache was up to date, and the web host's DNS was up to date… good to go!

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.