How Do I Change My Hosts File
What is a Hosts File?
The hosts file allows you to set IP addresses for a domain on your local computer that may override the authoritative DNS. It allows you to see what a domain will display if it is pointed to a different server.
This article covers the following topics:
How to Recognize a Hosts File?
The hosts file is a plain text file and is usually named hosts. A typical hosts file will have one or more lines referencing your local computer (as 'localhost') and will resemble this:
- 127.0.0.1 localhost
- 123.45.67.89 www.example.com
- #98.76.54.32 www.another-example.com
A hosts file can be modified to override your network settings and allow your local machine to view a website before the DNS changes propagating.
Why Change the Hosts File?
Changing your hosts file is a temporary measure to preview your site as it will load from your HostGator server. It lets you make changes on a server other than the one loaded by your domain when visitors access your page.
Hosts File is handy for development purposes, as you can work on your site on an alternate server using a hosts file while visitors may still visit and use your existing site.
How to Edit Hosts File
To change the host your domain loads from, you need to know your server's correct IP. HostGator servers will require you to use the IP address displayed in your cPanel.
Your Shared IP address is located in the General Information section on the right-hand side of your cPanel.
You may change the host your local computer loads your website from by directly editing your system's hosts file. This method will be more straightforward if you are an experienced user of your local PC's operating system.
All operating systems will have a hosts file like our example:
- 127.0.0.1 localhost
- 123.45.67.89 www.example.com
- #98.76.54.32 www.another-example.com
Add the second line in this example to your hosts file, with the following edits:
- Replace 123.45.67.89 with the IP address from your cPanel.
- Replace www.example.com with your actual domain name.
You may deactivate a line to undo this change by prefacing it with a # (as in the third line above). It will cause the line to be ignored.
Below are instructions on how to make this change in your operating system. We also created a video tutorial to guide you on the steps.
Here's a video tutorial on how to change Hosts Files on your local computer.
Windows 8 and Windows 10
- To find the Windows hosts file location: Select the Start key and locate Notepad. (If you do not see it on your current Start page, begin typing Notepad, and a search box will appear on the right side of the screen with a list of programs under it. Notepad should be at the top of this list.
- Right-click on Notepad. You will see options appear on the bottom portion of the Start Page.
- Select Run as administrator.
Note: Performing this action may cause Windows User Account Control to prompt you with a warning, or if you are logged in as another user, a request for the Administrator password. This step is necessary to modify system files such as the hosts file.
- Click File in the menu bar at the top of Notepad and select Open.
- Click the drop-down box in the lower right-hand corner that is set to Text Documents (*.txt) and select All Files (*.*)
- Browse the Windows Hosts File location: C:\Windows\System32\Drivers\etc and open the hosts file.
- Make the needed changes, as shown above, and close Notepad.
- Save when prompted.
Windows 7 or Vista
- To find the Windows hosts file location: 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.
- Change the file filter drop-down box from Text Documents (*.txt) to All Files (*.*).
- Select hosts, and click Open.
- Make the needed changes, as shown above, and close Notepad.
- Save when prompted.
Windows XP and Earlier
- To find the Windows hosts file location: Browse to Start > Find > Files and Folders.
- Select the hosts file in your Windows directory (or WINNT\system32\drivers\etc).
- Verify that the file is not read-only by right-clicking it and choosing Properties.
- Open the file for editing with Notepad.
- There should already be an entry for localhost. Earlier versions of Windows have different formats for hosts file entries. Be sure to follow the same format as you find in your file when inserting the HostGator IP and the domain name:
On Windows 2000 and Windows ME, the order is IP address, hostname.
- Make the needed changes and close the Notepad.
- Save when prompted.
You may also need to reboot for the change to take effect. The next time you visit your domain, your browser will try to find the domain at the corresponding IP instead of looking up the IP through DNS.
Mac OS
Follow the instructions below to edit your hosts file if you are running Mac OS X.
- To locate Mac hosts files location: Navigate to the Terminal application. Start by typing Terminal on the Spotlight or by going to Applications > Utilities > Terminal.
- Open the hosts file by typing in the Terminal that you have just opened:
sudo nano /private/etc/hosts
Note: Some versions of Mac OS X will lock permissions on the hosts file (the file is marked as immutable). If this happens, use the following command instead:sudo chflags nouchg /private/etc/hosts.
- Type your user password when prompted.
- The hosts file contains some comments (lines starting with the # symbol) and some default hostname mappings (e.g., 127.0.0.1 localhost). Append your new mappings underneath the default ones. You can navigate the file using the arrow keys.
123.45.67.89 domain.com www.domain.com
- Replace 123.45.67.89 with the server IP that HostGator provided you in your cPanel.
- Replace domain.com with your actual domain name. Additional domains, subdomains, or addon domains (such as www.domain.com) can be added at the end of the line, separated by spaces.
- When done editing the hosts file, press Control-o to save the file.
- Press Enter on the filename prompt and Control-x to exit the editor.
Unix
On Unix-based systems, you can find the hosts file at /etc/hosts. Most distributions of Unix will have terminal located in the same location.
To open the terminal:
- Go to Menu.
- Select Applications.
- Choose Accessories.
- Select Terminal.
- Open the hosts file by typing in the Terminal that you have just opened:
sudo nano /etc/hosts
- Type your user password when prompted.
- The hosts file contains some comments (lines starting with the # symbol) and some default hostname mappings (e.g., 127.0.0.1 localhost). Append your new mappings underneath the default ones. You can navigate the file using the arrow keys.
123.45.67.89 domain.com www.domain.com
Replace 123.45.67.89 with the server IP that HostGator provided you in your cPanel. Replace domain.com with your actual domain name. Additional domains, subdomains, or addon domains (such as www.domain.com) can be added at the end of the line, separated by spaces. - When done editing the hosts file, press Control-o to save the file.
- Press Enter on the filename prompt and Control-x to exit the editor.
Flush DNS
Once you have modified your hosts file, it is recommended that you flush your DNS so that the new changes can be implemented more swiftly. DNS flushing must be done using the command line. Depending on your computer's OS, there will be different commands.
For more information on Flush DNS, please see the following related article: