Modifying Hosts file
This should be done by an advanced user. You will want to either make a copy of your host file prior to making changes, so you can revert it back when the site is live, or keep a record of the file so you can change it back.
Modifying your hosts file will allow you to override the DNS for a domain, on that particular machine. This can be used to test your site prior to going live with an SSL, pointing the domain name, 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 at the bottom of your hosts file for example will point rhino.acme.com and x.acme.com to the specified IP address.
Your host file will be located in the following path for Windows C:\Windows\System32\drivers\etc
Once you have the lines you need in your hosts file, you will also need to run the following command in a command prompt for your updates to the hosts file to take effect:
After you have finished viewing the site, you will want to remove the changes made to your hosts files and run the command prompt command again to have the site run on it's set DNS.
Host File Location for Windows 7 or Vista
Host File Location for Windows NT/2000/XP
- Browse to Start > All Programs > Accessories
- Right click "Notepad" and select "Run as administrator"
- Click "Continue" on the UAC prompt
- Click File-> Open
- Browse to "C:\Windows\System32\Drivers\etc\hosts
- Change the file filter drop down box from "Text Documents (*.txt)" to "All Files (*.*)"
- Select "hosts" and click "Open"
- Make the needed changes, and close Notepad. Save when prompted.
Host File Location for Linux
- Click Start > All Programs > Accessories > Notepad
- Click File > Open
- In the filename field type C:\Windows\System32\Drivers\etc\hosts
- Click Open
- Open a terminal window
- Type sudo nano /etc/hosts (you can use any text editor)
- Enter your password
Host File Location for Mac OS X 10.0 - 10.1.5
1. Open /Applications/Utilities/NetInfo Manager.
2. To allow editing the NetInfo database, click the padlock in the lower left corner of the window.
3. Enter your Admin password and click OK
4. 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.
5. The quickest way to create a new entry is to duplicate an existing one. So select the "localhost" item in the third column.
6. Choose Duplicate from the Edit menu. A confirmation alert appears.
7. Click Duplicate. A new entry called "localhost copy" appears, and its properties are shown below the browser view.
8. Double-click the value of the ip_address property and enter the IP address of the other computer.
9. Double-click the value of the name property and enter the hostname you want for the other computer.
10. Click the server property and choose Delete from the Edit menu.
11. Choose Save from the File menu. A confirmation alert appears.
12. Click Update this copy.
13. Repeat steps 6 through 12 for each additional host entry you wish to add.
14. Choose Quit from the NetInfo Manager menu. You do not need to restart the computer.
Host File Location for OS X 10.5 or later
1.Open the Terminal. It’s located at /Applications/Utilities/Terminal.app
2.Enter the following command: sudo nano /private/etc/hosts
3.This command is using nano, the built-in command line editor to open the Hosts file. You will be asked for your password because root privileges are needed to edit the Hosts.
4.You will now see the contents of the Hosts file. It has one entry per line, with the hostname followed by the IP address. Hashed lines (#) are comment lines and are ignored by the system. Use the arrow keys to move the cursor.
5.Append your entries to the end of the file. Use tab key or spaces to separate the IP from domains.
6.Check you entries, and Save the file by pressing Control + O keys. (letter O, not zero) It will ask where to write, with the Hosts file already typed, press Enter to write.
7.Control + X to close nano editor.
8.Now for your new entry to take effect, the DNS cache needs to be flushed.