Knowledge Base Hub

Browse through our helpful how-to guides to get the fastest solutions to your technical issues.

Home  >  Domain Name & DNS Issues  >  How to edit hosts file in Windows and Linux operating system?
Top Scroll

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

 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

For our Knowledge Base visitors only
Get 10% OFF on Hosting
Special Offer!
30
MINS
59
SECS
Claim the discount before it’s too late. Use the coupon code:
STORYSAVER
Note: Copy the coupon code and apply it on checkout.