What is a hosts File Modification?
A hosts file modification is a simple tweak that is used to “trick” your computer into resolving to a specific IP. This is especially useful when developing your site on our server when your nameservers are not pointed to us yet. This is necessary when you are working with domain-name-dependent software (ie: Content Management System (CMS), such as Joomla! or WordPress).
How Does a hosts File Modification Work?
The image (to the right) depicts the process of resolving a domain to an IP address using various devices. In the image, the hosts file on “Your Computer” has been modified with the following code:
22.214.171.124 example.com 126.96.36.199 www.example.com
Since the hosts file was only modified on “Your Computer“, only that device will resolve the domain: example.com to the IP address: 188.8.131.52.
Other devices, that do not have the hosts file modified, will resolve to the IP address: 172.16.0.0, found in the DNS zone–present in the name servers that the domain is pointed to.
How to Modify Your hosts File
Follow the sections below to learn how to perform a hosts file modification.
Run Notepad as administrator
To modify your hosts file, you will need to first run Notepad (or any other text editor available to you on the same computer) as administrator. This is because the hosts file is a system file and cannot be modified without elevated privileges. Note: If you are running Windows XP or lower, you won’t need to run it as administrator as this functionality only exists in Vista and above. Locate Notepad within your Start menu. If it is not already there, you can type “notepad” into the search box to show it. Then, right-click on it and click on “Run as administrator”.
Open Your hosts File
After you have Notepad up and running as administrator, you can then locate your hosts file and open it. While not all Windows versions store it in the same place, it is typically located within c:\windows\system32\drivers\etc and the filename is: hosts. If you do not see it there, other possibilities are as follows:
- Windows 95/98/Me c:\windows
- Windows NT/2000/XP Pro c:\winnt\system32\drivers\etc
- Windows XP Home/Vista/Windows 7 c:\windows\system32\drivers\etc
- Windows 8 c:\windows\system32\drivers\etc
- Windows 10 c:\windows\system32\drivers\etc
Now, you need to open your hosts file. With Notepad already open, click on “File”, then “Open…”. As the hosts file is not a standard .txt file that Notepad will look for by default, you will need to change the drop-down in the bottom right that says “Text Documents” to select “All Files”. Finally, navigate to the location of your hosts file and double-click on it to open the file using Notepad.
Find the IP Address Associated with Your Account
- Log into cPanel
- To the right, you should see a column of stats describing your account. Look for Server Information and click on that link.
- Scroll down to where you see “Shared IP address”. If you have a dedicated IP, it will say “Dedicated IP” instead. This is the information that you will need for your hosts file mod.
Edit Your hosts File
Now that you have the correct file open, it’s time to modify your hosts file. Within your hosts file, you should see something similar to the following:
# Copyright (c) 1993-1999 Microsoft Corp. # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # This file contains the mappings of IP addresses to host names. # Each entry should be kept on an individual line. # The IP address should be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one space. # Additionally, comments (such as these) may be inserted on individual lines # or following the machine name denoted by a '#' symbol. # For example: # 184.108.40.206 rhino.acme.com # source server # 220.127.116.11 x.acme.com # x client host 127.0.0.1 localhost
- In Notepad, click on “File” and select “Save As…”
- In the file name, enter something you will remember such as hosts_file_09.16.2013
- Click “Save”
Using the information you have gathered you will add some lines to your hosts file. They will look something like this:
18.104.22.168 my-wordpress-site.com 22.214.171.124 www.my-wordpress-site.com
After making the change, click on “File”, then “Save”. You have now made your hosts file modification.
Additional Windows 8/10 Necessary Steps
Configuring Defender in Windows 8 to Modify Your hosts file
If you are using Windows 8, Windows Defender is running by default and it prevents you from being able to modify your hosts file. You will need to allow this file to be edited by going into Windows Defender and performing the following steps:
- Navigate to Windows Defender by hovering over the right corner to bring up the navigation bar. Click on the icon that appears to be a magnifying glass to start a search. Type in “Windows Defender”, click on the icon that appears. It will be labeled “Windows Defender.” Click on this icon and the application will launch.
- When Windows Defender opens, click on the tab labeled Settings.
- Next, type in the location of the hosts file based on the location of the Windows installation. Here’s the default path: c:\windows\system32\drivers\etc\hosts
- Click on the Add button and you’ll see it added to the list beneath the file locations.
- Click on Save Changes in the bottom right and then close Windows Defender.
- The next step will be actually editing the file. As per the instructions above, you will need to edit the file as an Administrator. Hover over the right side again, and then search for “Notepad”. Open it as an administrator.
- Open the file as per your HOSTS file path.
- Make your edits, and click on SAVE by clicking on “File” to bring up the menu. This completes the HOSTS file edit in Windows 8.
Working with Windows 10 to Change Your Hosts File
When you are working with Windows 10, the main concern you will need to address before you begin is being able to modify your hosts file. You will need Administrator access in order to make the change. If you have any questions concerning administrator access please see Microsoft’s definition of an Administrator for Local accounts or speak with a local Windows administrator. In Microsoft’s documentation, local accounts means “on your computer.” Follow the steps below to quickly and easily make changes to the hosts file.
- Log in as your Administrator User
- Right-click on the Windows icon in the toolbar.
- A pop-up menu will appear. Look for Powershell (Administrator) then click on this option.
- You will see a Window notification pop-up asking if you wish to allow permission for the application to make a change. Click on Yes to continue.
- When the prompt appears, type in Notepad. Since you are launching Notepad from the Powershell Administrator, it will launch the application with the appropriate administrator permissions.
- In the Notepad menu, click on File, then click on Open. You will need to navigate to the folder that contains the hosts file. This is the typical path: c:\Windows\System32\drivers\etc.
- If you do not have show hidden files enabled in your Windows File preferences, you will not see any files. However, type in Hosts, then hit enter. Notice that the file does not have an extension – it’s just “hosts.” This will bring up the Hosts file. Since the Hosts file is a system file, it will be hidden unless you set your Windows file preferences to show hidden files.
- At this point, you will see the hosts file. As per the instructions above you will need to have the IP address of the server where you trying to point the URL. Make sure that you follow the example provided and put a space between the IP address and the domain name that you wish to use.
- Click on File, then click on SAVE in order to save any changes that you may have made to the file.
As a precaution close the Notepad window and then re-load the hosts file per the beginning steps and double-check to see that your changes have been applied.
How do I know that it worked?
The easiest way to see that it worked is to just go to your domain. Does it show your new site as it should on our servers? If there were no changes to your site from when you moved it, you might need to run a ping test to ensure that it shows the correct IP.
Flushing Your DNS Cache
After you modify your hosts file, if your computer has cached your DNS, you will need to clear it. Luckily, we have an article that can teach you how to do just that:
Learn more about DNS server management with our Managed VPS Hosting Product Guide.
Get better performance and security with our ?VPS Hosting.