Knowledge Base
MilesWeb / Domain Name & DNS Issues

How to edit hosts file in Windows and Linux operating system?

Approx. read time : 5 min

Watch this video for a step by step process on how to edit hosts file in Windows and Linux operating system

The hosts file is used to map domain, hostnames to IP addresses. Using the hosts file you can point any domain name OR hostname to the desired IP on your local machine.

The hosts file is a massive help when an individual/webmasters/developers want to test website design, code on domains that are not registered OR do not point to the desired server IP. Don’t need to wait for DNS to propagate when pointed on a different web server.

Follow these steps to add new entries in the host file for the Windows operating system:

  • Click on Start button and type notepad.
  • Right click on Notepad and select the option “Run as administrator” to open Notepad.
  • Now, go to File and click on Open.
  • Click on This PC.
  • Select Local Disk C drive
  • Go to Windows folder.
  • Click on System 32 folder.
  • Choose drivers folder.
  • Now, select etc folder.
  • As you can see no files are showing in this folder.
  • To change the view from text document to all files, simply navigate to this drop down and select all files option.
  • Select the hosts file and click on Open.
  • In the same file, enter the IP address and domain name as per your choice.
  • You can use external IP address provided by your new hosting provider if you wish to test how your website is loading on that IP address before updating its DNS of your website.
  • Here, we have entered local host IP address i.e. 127.0.0.1 and www.milesweb.com as a domain name.
  • Navigate to File and click on Save to save the file.
  • Now close this window.
  • To test this hosts file, again go to search box, type cmd, and hit enter.
  • The command prompt window appears on the screen.
  • Type the command ping space website name i.e. www.milesweb.com in our case and press enter.
  • Now you can see milesweb resolving to local host IP address rather than MilesWeb’s external IP address.

Follow these steps to add new entries in the host file for the Linux operating system:

  • To open the terminal on ubuntu press the shortcut keys Ctrl + ALT + T simultaneously.
  • In the terminal window type this command sudo nano /etc/hosts and press enter.
  • Type the password of your PC.
  • The file will directly get open.
  • Enter the IP address and domain name as per your choice.
  • Here, we have entered local host IP address i.e. 127.0.0.1 and www.milesweb.com as a domain name.
  • Press CTRL + X simultaneously to save this file.
  • It will ask for the confirmation, in that press y and hit enter.
  • Now, type this command ping space website name and press enter.
  • As you can see milesweb resolving to local host IP address rather than MilesWeb’s external IP address.

That’s how you can edit hosts file in Windows and Linux operating system.Save

With over 10+ years of experience in the web hosting industry, I have achieved extensive exposure to result-oriented methodologies. And expertise in different domains like Datacentre Services, Cloud computing technology, Web hosting industry and many more.
Need help? We’re always here for you.