Skip to content

Getting started

A hosts file that does not fight you

Map a name to an IP on your laptop for a clean preview, then remove the line so public DNS wins again.

Updated Aug 29, 20263 min read13 reads
A hosts file that does not fight you
Preview a site with your hosts file, then clean it up

A hosts file that does not fight you is a short, correct mapping of a domain name to an IP on your own computer only. You use it to preview a site before DNS changes, then you remove the line so your laptop matches everyone else again.

It never changes public DNS. Your phone on cellular, a coworker, and curl from a VPS still use the real records. That is useful during a rehearsal and confusing if you leave the line in place while you debug “the live site.”

Add a clean hosts line

Put one line per name, and include www if you use it. On Windows the file is C:WindowsSystem32driversetchosts. Open it as Administrator, save without a BOM, and avoid editors that write UTF-16. On macOS and Linux the path is usually /etc/hosts, and you need elevated rights to save.

Browsers and the operating system both cache lookups. After you save, flush DNS on the machine and test in a private window. A private window plus a quick curl check is clearer than digging through browser internals.

bash
getent hosts example.com; curl -sI https://example.com | head

getent hosts shows what this machine will use after name resolution. If it still prints the old IP, the line did not apply. Check syntax, a stray comment character, or whether you could actually write the file. The curl headers show whether that IP is the server you expect. Match both before you decide the site copy is wrong.

Share previews without a team hosts edit

A full team should not all edit local hosts files. Give them something like staging.example.com protected with Directory Privacy instead. That keeps the rehearsal off each person’s laptop and avoids mixed results.

Remove the line when you are done

Delete the hosts entry when you point nameservers or finish the preview. Future you will not remember why only your machine looks “wrong.” A migration ticket can note that you used a hosts preview; the checklist for what to send lives in what to send for a cPanel migration.

Our nameservers are ns1.logicweb.com and ns2.logicweb.com when you are ready for public DNS. Until then, keep the hosts file short, verified, and temporary.

Share

Send this article

Need someone else to do this? Send them the link — the commands are in the article.

Was this article helpful?

Be the first to rate this article.