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 22.214.171.124 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 –
The windows Hosts file is the first place the computer searches to resolve a name when seeking an IP address. Hosts files convert domain names or NetBIOS names into IP addresses. If the name is not in the local hosts file, the computer then tries to resolve using a Domain Name Service (DNS). If it’s still not found, the look-up procedure fails. Here is an example of hosts file line: When you search for www.google.com, the computer translates the domain into 126.96.36.199, which happens to be Google’s local host IP address. There are many reasons why users must know their windows hosts file location. We are going to share the Windows file server configuration customization tips and tricks. Before that, it’s crucial to know why you may need to modify the windows hosts file in the first place.
Top reasons to modify the hosts file
Modifying the hosts file on your computer is super easy to do and can be incredibly useful. Here are the three major reasons why modifying hosts file can be a good idea.
Test a website’s development
Running your web application on localhost during development is necessary for validation. Localhost, 127.0.0.1, or localhost IP addresses can all be used to run websites. However, since the localhost has various restrictions, you should test your website on a custom domain before launching it on the public domain. Let’s take an example of an online store. Suppose, you want to debug payment gateway issues, but your payment gateway is not supporting the localhost URL in the case of successful payment. In such scenarios, the hosts file allows you to specify a custom domain, and localhost can be used to verify the payment process. If you are unsure how all these things work, you can always hire a managed services provider that provides managed Windows server solutions to enhance your web development process.
Block a website
Using the hosts file, you can block risky websites and those that you don’t want your kids to visit. You have complete control over anything you choose to prohibit, including the majority of hijackers and undesirable programs. You can block risky websites simply by adding the domain addresses of all spyware websites and ad networks to your hosts file. The hosts file can be modified to block websites, networks, and spyware.
You can use the Hosts file to block trackers, adverts, banners, third-party page counters, marketing, or third-party websites in order to protect your privacy. It can serve as your local system’s firewall. You can block trackers, adverts, banners, third-party page counters, marketing, or third-party websites, among others, ensuring privacy protection.
Is it safe to modify Hosts file?
From a general point of view, modifying windows hosts file is a safe process and there aren’t any risks associated with the action. At the end of the day, you must know what you are up to. If you are looking for ways to test your web projects during the development stage, it always helps to have professional managed services providers assisting you.
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.
Also Read-4 Things to Look for when Choosing a Window Web Hosting Provider
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.