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 The Hosts File In Windows, Linux, and macOS Operating Systems?
Top Scroll

How To Edit The Hosts File In Windows, Linux, and macOS Operating Systems?

 3 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 Mac users (Apple macOS):

  • Open the Terminal: To open the Terminal, press Command (⌘) (Command key symbol) + Space and use Search for Finder.
  • Open the Hosts File: Now, input the command:

sudo nano /etc/hosts

When prompted, provide your Mac password.

  • Edit the Hosts File: Look for the arrow keys to navigate to the bottom of the file. Add the following entry:

123.123.123.123 example.com

(Make sure to replace 123.123.123.123 with the actual server IP and example.com with your domain.)

  • Save and Exit: In the step before this, you pressed Control + X. Now, you have to press Y and then press Enter to save.
  • Flush DNS Cache: Run the command below to apply changes:

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

There are no explicit messages; the changes will be effective immediately.

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 the hosts file in the Windows, Linux, and macOS operating systems.
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.