Location of HOSTS files

A handy little reference on the use and location of HOSTS files on Ubuntu, Windows Vista and Windows XP.

A good practice in the final development stages of new sites and is testing them on the final server location without adjusting the DNS servers to point that IP (the IP address of the final site location) This concept is good for thoroughly testing your site on the live server and ensuring all works as it should before actually pushing it "live".

The HOSTS file tells the browser to which IP address it should go for a particular domain name. Let's say I have been working on my site at public IP 192.168.1.5 and my domain is www.mydomain.com. Just go into your HOSTS file and add this entry:

192.168.1.5 www.mydomain.com

My Ubuntu hosts file looks like this:

view plain print about
1127.0.0.1 localhost
2127.0.1.1 name-ubuntu-main
369.41.252.133 www.a-alleviative.com
469.41.252.133 joemura.com
569.41.252.134 www.cfjoe.com

My Windows Vista machine looks almost the same, except for the additional MS comments on top.

Note that in order to go to the site from your PC, you must use the exact domain as in the HOSTS file. If I was to type my domain.com into my browser I would end up in the wrong place. Lets take a look at cfjoe.com from my Ubuntu machine by pinging.

view plain print about
1coldfusionjoe@admin-ubuntu-main:~$ ping -c3 www.cfjoe.com
2PING www.cfjoe.com (69.41.252.134) 56(84) bytes of data.
364 bytes from www.cfjoe.com (69.41.252.134): icmp_seq=1 ttl=52 time=12.7 ms
464 bytes from www.cfjoe.com (69.41.252.134): icmp_seq=2 ttl=52 time=13.1 ms
564 bytes from www.cfjoe.com (69.41.252.134): icmp_seq=3 ttl=52 time=12.1 ms
6
7--- www.cfjoe.com ping statistics ---
83 packets transmitted, 3 received, 0% packet loss, time 2003ms
9rtt min/avg/max/mdev = 12.149/12.689/13.122/0.424 ms
10
11coldfusionjoe@admin-ubuntu-main:~$ ping -c3 cfjoe.com
12PING cfjoe.com (69.41.252.133) 56(84) bytes of data.
1364 bytes from www.a-alleviative.com (69.41.252.133): icmp_seq=1 ttl=52 time=11.6 ms
1464 bytes from www.a-alleviative.com (69.41.252.133): icmp_seq=2 ttl=52 time=12.1 ms
1564 bytes from www.a-alleviative.com (69.41.252.133): icmp_seq=3 ttl=52 time=11.1 ms
16
17--- cfjoe.com ping statistics ---
183 packets transmitted, 3 received, 0% packet loss, time 2003ms
19rtt min/avg/max/mdev = 11.121/11.657/12.158/0.442 ms

My hosts file has the IP address of 69.41.252.134 for www.cfjoe.com and nothing for cfjoe.com. Pinging cfjoe.com shows an IP address of 69.41.252.133 where my DNS servers currently have the domain parked.

The hard part is finding the HOSTS file to edit on a regular basis. I have a shortcut on all my Windows workstations to easily open and edit. Not so on Ubuntu, but it's easy enough to find – but not remember!

Ubuntu hosts file location: /etc/hosts

On Windows Vista and XP C:\Windows\System32\drivers\etc\hosts

The HOSTS file has no extension. The directory paths above are to the actual file.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
BlogCFC was created by Raymond Camden. This blog is running version 5.9.7. Contact Blog Owner