Geeklog: What I Learnt Today / Adam

Altering your hosts file

> To change your laptops DNS so it points somewhere different to the real DNS online. You might want to do this if you have a website on a new server and you want to check it before the rest of the worlds DNS switches over. The downside is you have to remember that your laptop may well be pointing at something different to people you talking to.
In terminal first make a copy of the file in case you cock it up

sudo cp /etc/hosts /etc/hosts-pre-editing
then open the directory

open /etc/
if your happy in vi or have a text editing program set up in your terminal go straight to editing it
sudo vi /etc/hosts
Then you can right click and open with your chosen code editor. You want to be editing this in a text editing program TextWrangler, BBEdit, TextMate or Vi rather than something like Word which will make more changes than you can see. The file will look something like below. You don't want to be editing any existing lines.

# Host Database
# localhost is used to configure the loopback interface
# when the system is booting.=C2=A0 Do not change this entry.
##       localhost broadcasthost
::1             localhost
fe80::1%lo0     localhost

At the bottom of the file add a line like so example.com

Once you have made a change you probably want to refresh your DNS cache on the version of OS X I'm using (10.12) that is

|sudo dscacheutil -flushcache;sudo killall -HUP mDNSResponder; |

Then when you restart your browser you should be seeing the example.com at rather than where ever its set to be in DNS globally.

/ Adam