Previewing Websites Without DNS

Sometimes, you may want to preview your newly deployed website before you update its DNS settings. The redirect of DNS can also take awhile to you want to make sure everything is working if you have moved to a new server. This can also be useful when you’re creating a brand new website, or want to test your name-based virtual hosting configuration or another DNS-related feature. By making the changes described below, you can test your new setup from your local computer without affecting global access to your domain’s current location.

The Hosts file

In the early days of Internet, there where no DNS that looked up domains to IP. Instead every computer had a file containing domains and IP-numbers. Modifying your hosts file enables you to override the DNS for a domain, on that particular machine. This is useful when you want to test your site without the test link, prior to going live with SSL; verify that an alias site works, prior to DNS changes; and for other DNS-related reasons. Modifying your hosts file causes your local machine to look directly at the IP address specified.

Find the IP of your server.

This can depend on your host.

Open your Terminal and type:

nano /etc/hosts

Add your server’s (external) IP to the Hosts file

Flush your DNS cache

For Yosemite, El Capitan, Sierra (10.10.4 and later)

sudo killall -HUP mDNSResponder
Need a simple way to do smarter deployments? Take a look at GitFTP-Deploy. Try free for 7 days.