When migrating a domain over to a new provider, one of the things that you might run into is the need to wait a day or two for the DNS record to propagate. DNS is the service that maps your host name to an IP address that can be resolved on the network.
Something that a lot of people may not know is that you can bypass DNS entirely on your local computer by editing your /etc/hosts file. The /etc/hosts file contains static linkings between hostname and IP address. It’s been used in the Linux world for a long time. However, windows puts it in a strange place. In Windows Vista and Windows 7, the file name is:
You’re also going to need administrate privileges to edit the file. The easiest way to do it is to simply use notepad. Search for notepad using the windows start button, but rather than left-clicking on notepad, right click and select “Run As Administrator“. Windows will do the usual user access control screen flash and prompt you to ok administrator privileges. Once that’s done and notepad is on screen, simply use File:Open and enter the pathname
Entries in the file are pretty simple. They’re just an IP address followed by some whitespace and a list of hostnames. For example, if I wanted to link the IP 123.456.789.012 to both www.mysite.com and mysite.com, I could enter the following:
123.456.789.012 www.mysite.com mysite.com
Make sure not to mess with the entries for 127.0.0.1, ::1, or localhost. Those are special entries that programs on your computer can use to identify your computer itself.
Remember that once your domain names changes actually take affect in the DNS system to remove the manual settings from the hosts file. If you leave them in permanently, then you would be masking potential DNS failures as well as setting yourself up for a great deal of confusion in the future if your provider ever changes your IP address.
I found this technique pretty handy for migrating new domains over to my shared hosting account. I could create the new site on the new provider, migrate all of the files and get the site setup using the changes that I wanted, and then do the little
hosts trick to preview the site as it would appear to users. Once everything was to my satisfaction, then I contacted the domain registrar to move the actual DNS records.
One potential gotcha — I found that occasionally it would take a while for applications on the computer to learn of the changes to the
hosts file. This was particularly bad with Internet explorer. If you have a web browser open and looking at the hostname before you change, you might need to exit the browser and restart it for the changes to take effect. In the worst case, rebooting your computer would solve the issue.