Skip to content

Monday, November 30th, 2009

New Linux User

Explanation: Using /etc/hosts

July 28, 2006 by Jon  
Filed under Explanation

In the comments section of a recent post, I mentioned that I used my /etc/hosts file to test out a site after moving it to a new server. Instead of leaving it in the comments, I thought I would pull that knowledge out into a post.

As regular readers can probably surmise, I’ve been doing an awful lot of host-moving these days. In the past week I’ve moved all 10 of my domains twice. I’ve moved domains before, but never on such a grand scale and never more than once in a week. It sucked, but I learned a few things such as using the /etc/hosts file.

When you move a site, the IP address of that site will change. To let the world know that your IP address has changed, you need to update your DSN records however it can take days for that information to propagate throughout the world. It’s very hard to thoroughly test a newly-moved website until DNS resolves and waiting for that to happen just to find out that your newly live site has errors in it isn’t a lot of fun. A much better way is to move the site, but leave your DNS settings alone so the rest of the world continues to see your old site, and make a change to your /etc/hosts file so only you can see the new site.

When you attempt to reach an Internet address – regardless of whether your browsing, ssh’ing, emailing, or whatever – your system consults its /etc/hosts file to see if it has an IP address entry for the domain you’re looking for. If it doesn’t (as is the case most of the time) it then queries the DNS system for an IP. To ensure that you will see the new site, edit your /etc/hosts file and, underneath the existing 127.0.0.1 lines, put in your new IP address and your domain on the same line. For example, when I moved Linux World Net, I added these lines to my /etc/hosts file:

69.65.105.227 linuxworldnet.com
69.65.105.227 www.linuxworldnet.com
69.65.105.227 fifo.linuxworldnet.com
69.65.105.227 security.linuxworldnet.com
69.65.105.227 gaming.linuxworldnet.com
69.65.105.227 linuxbiz.linuxworldnet.com
69.65.105.227 mythdispeller.linuxworldnet.com
69.65.105.227 gaming.linuxworldnet.com
69.65.105.227 learning.linuxworldnet.com
69.65.105.227 minimum.linuxworldnet.com
69.65.105.227 news.linuxworldnet.com
69.65.105.227 naked.linuxworldnet.com

Now, whenever I attempt to go to any of theses addresses, I get the new site. Nobody else in the world does, however, because I haven’t updated my DNS records yet. Once I’ve determined that the site is working properly, then I can change the DNS settings at Zone Edit (or your registrar) and the rest of the world can come on in.

Note: I suspect, but have not tested, that something like *.linuxworldnet.com might have worked as well.

Reader Eric left a tip that will speed up DNS propagation once you get to that step. Thanks, Eric:

About 24 hours before you move a domain, update your TTL settings for the domain that you’re going to move to 600 (seconds). The default in WHM is 14400.

This will tell DNS servers to check the server every 600 seconds (5 minutes) to update the DNS. So, once you switch you’ve moved the site and updated your nameservers, all traffic should be redirected to the new site in about 5 minutes.

  • StumbleUpon
  • Digg
  • Facebook
  • Mixx
  • Google
  • TwitThis
  • Reddit
  • Yahoo! Buzz
  • Slashdot
  • E-mail this story to a friend!

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!


About Us | Advertise with us | Blog for EveryJoe | Privacy Policy | Terms of Use
Get This Theme | Sitemap


All content is Copyright © 2005-2009 b5media. All rights reserved.