Every site hosted on a server running an operating system contains a host file that helps in mapping domain names and IP addresses. The hosts file contains IP addresses followed by a domain name (separated by a space). For instance, if you want to reach www.google.co.in, the hosts file on Google’s server will contain the IP address 126.96.36.199 followed by the url www.google.co.in. Whenever there’s mapping of the IP address with the domain name in the hosts file, the computer will not query the DNS server to establish a connection with a remote device, but directly read the IP address from the hosts file to process the request. Every OS has a hosts file and you can make amendments to allow it to accept more domain name requests. Add the desired mapping entries and the changes will start working without rebooting the server. This blog post takes you through the paces on how you can modify and configure the hosts file on windows server.
How to modify & configure the hosts file on Windows Server –
Why Hosts File Modification?
Hosts file modification is done to trick the server into resolving to specific IPs. The method is extremely useful when your website, though hosted on a server, is still in the developmental stage and name-servers are not pointed anywhere. It is also used to block particular websites.
Configuring the Hosts File
1. Run Notepad as Administrator
The hosts file is a system file, you cannot modify or configure it as a simple user. You need administrator level permission to make the changes, therefore, run Notepad as an administrator. Do this if you are working with Windows Vista or higher, but simply open the Notepad if you have Windows XP or anything before that. Locate Notepad in the Start menu, right-click on it and select the “Run as administrator” option.
2. Locate Hosts File
After opening Notepad as an administrator, locate the hosts file. It is usually located at c:\windows\system32\drivers\etc\hosts, but not all Windows versions store it in the same place. In case you do not find it, explore other possibilities:
- Windows 95/98/Me -> c:\windows\hosts
- Windows NT/2000/XP Pro -> c:\winnt\system32\drivers\etc\hosts
- Windows XP Home/Vista/Windows 7 -> c:\windows\system32\drivers\etc\hosts
- Windows 8 -> c:\windows\system32\drivers\etc\hosts
- Windows 10 -> c:\windows\system32\drivers\etc\hosts
After locating the hosts file, switch to Notepad and click “File”, then “Open…”. Hosts file is not a standard .txt file that Notepad looks for by default, you will have to do a bit of troubleshooting to make the file appear in the dialog box. Change the dropdown option displaying “Text Documents” to “All Files(*.*)” Now that you see all files, navigate to the hosts file, double-click it, and it will open in the Notepad.
3. Overhaul Windows Defender (Windows 8)
Windows Defender running on Windows 8, by default, prevents the modification of the hosts file. You have to change the configuration of Windows Defender so it can allow you to edit the hosts file.
- Search for Windows Defender through the navigation bar and click to launch the application.
- On the launch tab, click on ‘Settings’.
- Type the location of the hosts file, which is c:\windows\system32\drivers\etc\hosts.
- Click on the Add button to append it to the list beneath file locations.
- Save the changes by clicking on the option located at the bottom right, and then close the app.
- You can now edit the hosts file by following instructions given above.
- After making the edits, save the file to complete the hosts file edit.
4. Get Administrative Permission to Modify (Windows 10)
In Windows 10, you must access text editor as an administrator to carry out the necessary changes to the hosts file. To do that, you may have to log-in as an administrator to be able to save your changes.
5. Locate Associated IP Address
The IP address is easily traceable. It is located within the cPanel through the following steps:
- Log into cPanel
- Click the “Expand Stats” section to the left of the screen to see more information about your account.
- Scroll down to “Shared IP address”/”Dedicated IP”. Copy or note the IP to modify your host file.
6. Modify the Hosts File
After getting the IP address from the cPanel, add a few lines to your hosts file, including the IP address and domain name. It will look like
Save the changes by clicking on “File”, then “Save”. The hosts file configuration is complete.
7. Test the Modified File
Now that everything is complete, it is time to test the changes. Type in the URL and see if you are redirected to your new site. In case the site does not reflect any changes after being moved, run a ping test to ensure it is directing to the correct IP address.
All Configured and Ready to Deploy!
Hosts file is a powerful tool that you can use to manipulate Domain Name Resolution to suit your needs. Additionally, you can use it to block malicious programs to ensure your computing environment is a lot more secure. I2k2 Networks (P) Ltd. is one of the leading data center, hosting and technology services company providing comprehensive expert server management, hosting solutions, and 24/7 no-obligations assistance. To know more about our comprehensive range of dedicated web hosting services and managed IT services, give us a call at +91-120-466 3031. You can also contact us by filling out the contact form and one of our executives will get in touch with you, shortly.