How to modify hosts file on local computer?
The hosts file is a computer file used by an operating system to map hostnames to IP addresses.
The hosts file is a plain text file, and is conventionally named hosts. Originally a HOSTS.TXT file and maintained centrally by Stanford Research Institute for the ARPANET, the hosts file predates the Domain Name System, which was first described in 1983 and implemented in 1984.
Prior to DNS, the hosts file was manually edited and served as a table of accessible hosts. It was due the size of the growing Internet and coincident growth of the hosts table that the more robust DNS was embraced and the hosts file supplanted.
Editing your hosts file will allow you to override the DNS for a domain, on that particular machine.
Can be used to test your site without the test link, prior to going live with SSL, verify an alias site works prior to DNS changes, or for other DNS related reasons.
This causes your local machine only to look directly at the IP specified.
Your hosts file will need to have two entries added that will contain the IP address you want the site to resolve to and the address. Adding the below two lines for example will point www.yourtesturl.com and yourtesturl.com to our current PHP5-ITK (“Refreshed” PHP5) cluster:
127.0.0.1 localhost loopback ::1 localhost or
127.0.0.1 www.yourtesturl.com
127.0.0.1 yourtesturl.com
Below is how to locate and edit the hosts file on several OS platforms. Once the proper domain information is added you will save the file and your system will begin resolving to the specified IP. Once testing is finished these entries should be removed.
Contents
- Windows 8
- Vista and Windows 7
- Windows NT/2000/XP
- Linux
- Mac OSX 10.0 – 10.1.5
- Mac OSX 10.6 – 10.8
Windows 8
Editing a HOSTS File in Windows 8
Here is what you can do in order to edit the HOSTS file on Windows 8.
- Copy the HOSTS file from the C:WindowsSystem32Driversetc folder to your Desktop.
- Open the copy from your Desktop in Notepad, and make all necessary changes.
Or directly open file location from NotePad or other PlainText editor like
Windows Vista and Windows 7
Vista and Windows 7 use User Account Control (UAC) so Notepad must be run as Administrator.
- Click Start -> All Programs -> Accessories
-
Right click Notepad and select Run as administrator
-
Click Continue on the “Windows needs your permission” UAC window.
-
When Notepad opens Click File -> Open
-
In the filename field type C:WindowsSystem32Driversetchosts
-
Click Open
Windows NT/2000/XP
- Click Start -> All Programs -> Accessories -> Notepad
-
Click File -> Open
-
In the filename field type C:WindowsSystem32Driversetchosts
-
Click Open
Linux
- Open a terminal window
-
Type sudo nano /etc/hosts (you can substitute any text editor)
-
Enter your password
Mac OS X 10.0 – 10.1.5
- Open /Applications/Utilities/NetInfo Manager.
-
To allow editing the NetInfo database, click the padlock in the lower left corner of the window.
-
Enter your Admin password and click OK
-
In the second column of the browser view, select the node named “machines.” You will see entries for -DHCP-, broadcasthost, and localhost in the third column.
-
The quickest way to create a new entry is to duplicate an existing one. So select the “localhost” item in the third column.
-
Choose Duplicate from the Edit menu. A confirmation alert appears.
-
Click Duplicate. A new entry called “localhost copy” appears, and its properties are shown below the browser view.
-
Double-click the value of the ip_address property and enter the IP address of the other computer.
-
Double-click the value of the name property and enter the hostname you want for the other computer.
-
Click the serves property and choose Delete from the Edit menu.
-
Choose Save from the File menu. A confirmation alert appears.
-
Click Update this copy.
-
Repeat steps 6 through 12 for each additional host entry you wish to add.
-
Choose Quit from the NetInfo Manager menu. You do not need to restart the computer.
Mac OS X 10.6 – 10.1.8
- Open Applications > Utilities > Terminal.
-
Open the hosts file by typing the following in the Terminal window:
sudo nano /private/etc/hosts
Type your user password when prompted
- Edit the Host File,The hosts file contains some comments (lines starting with the # symbol), as well as some default hostname mappings (e.g. 127.0.0.1 – local host). Append your new mappings underneath the default ones.
-
Save the Host File, When done editing the hosts file, press Control+x to save the file.
-
Make your changes take effect by flushing the DNS cache with the following command:
$ dscacheutil -flushcache
- New mappings should now take effect.
You must be logged in to post a comment.