Stop waiting for DNS servers – edit your hostfile

One of the issues I run into when transferring (or testing) a site is that, sometimes, you need the domain name for things to work properly. For instance, today I am transferring sites to Hetzner. But because of certain Joomla plug-ins I can’t open the site without it forwarding to an URL which shows me anything but the site I want to work on.

You could change the DNS settings for the domain and wait a long time before you could do anything. Or, you could edit your hosts file, and temporarely tell your Mac to look for your domain on another IP.

How it’s done

In order for this to work, the proper DNS entries must already be made on the target server. Your host will often do this for you, and then wait for you to point the domain in the proper direction. If these DNS entries exist, all you need to do is trick your Mac into looking for the domain at the new IP.

1. Open your Terminal

2. Edit the file /private/etc/hosts

3. Start a new line.

4. Enter the IP address, followed by the domain name you want to use.

5. Save the file

6. Try visiting the domain. You’ll end up on the new site, although your DNS settings haven’t propogated yet. Magic!