Summary

This article explains how you can quickly and easily edit your .hosts file in macOS and Windows.

A hosts file is a plain-text file used by your Mac or Windows computer to map hostnames to IP addresses.

Modifying your computers hosts file is a useful if you wish to preview your website on Ecenica without modifying your domain name. Editing your hosts file can also be useful after registering a new domain name, recent domain transfer or DNS update. See How long does it take for my domain name to become active?

How does it work?

When you view a website your computer looks at it’s .hosts file to try and map the site host-name to an IP address. If a match is not found, your computer tries to find an IP address using the Domain Name System (DNS).

Editing your .hosts file let’s you intercept the DNS lookup and redirect your domain to another IP address.

The computer at the receiving IP address needs to answer to your domain name.

Why update my .hosts file?

  • Easy migration. You can publish and test your site on your Ecenica web space without taking your old site offline.
  • Faster web development. You can develop and test your site on your local server using your domain name.
  • Redirect your domain to a local IP address.
  • Simple and easy to use.

How do I change my .hosts file?

To view your website before updating your domain’s name servers or DNS records you will need to change your HOSTS file to point to your Ecenica IP address (Computer).

On Mac? Try Gas Mask. A simple, and free hosts file manager for macOS Download Gas Mask

Apple macOS

  1. Open Terminal (Click Spotlight, or press Command+Space. Now type terminal.)
  2. Copy and paste the following code into Terminal
    sudo nano /etc/hosts
  3. Press Enter.
  4. Enter your Mac’s password
  5. Press Enter.
  6. Enter your Ecenica web site’s IP and domain name. See example below.
  7. Finish by pressing Ctrl+X and Y to save.
  8. Restart your browser before attempting to view your site.

Example showing adding 100.100.100.100 example.com to hosts file..

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost

##My Ecenica Websites
100.100.100.100       example.com

To save having to retype sudo nano /etc/hosts, when terminal opens, press the ‘up’ cursor key to scroll through the last actions.

Windows 10

  1. Click Search the web and Windows
  2. Type Notepad
  3. Right-click Notepad and select Run as administrator
  4. Click Yes on the User Account Control prompt
  5. In Notepad, click File > Open
  6. Change the file filter drop down box from ‘Text Documents (.txt)’ to ‘All Files (.*)’
  7. Right-click the address bar and select Edit address
  8. Type C:\Windows\System32\Drivers\etc and press the Enter key
  9. Select the hosts file and click Open.
  10. At the bottom of the file, insert your Ecenica web servers IP address and your domain name. For example: 100.100.100.100 example.com.
  11. Close Notepad. Click Save when prompted.

Example hosts file with 100.100.100.100 example.com added.

# Copyright (c) 1993-2009 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#

#My Ecenica Websites
100.100.100.100       example.com
100.100.100.100       www.example.com

Flush DNS

After you’ve changed your hosts file we recommend you flush your DNS. This will make your PC pick-up the new changes faster.

  1. Click Start.
  2. Type cmd.
  3. Right-click Command Prompt and select Run as administrator.
  4. Click Yes on the User Account Control prompt.
  5. Enter ipconfig /flushdns
  6. Press the Enter key.

Microsoft Windows 8

  1. Open Start Menu (Ctrl+Esc).
  2. Type “Notepad”.
  3. Right click “Notepad” and select “Run as administrator”
  4. Click Yes on the User Account Control prompt.
  5. Click File -> Open.
  6. Change the file filter drop down box from “Text Documents (*.txt)” to “All Files (*.*)”.
  7. Browse to “C:WindowsSystem32Driversetc”.
  8. Select “hosts” and click “Open”.
  9. Insert your Ecenica web servers IP and domain name. For example: 100.100.100.100 example.com.
  10. Close Notepad. Click Save when prompted.

Microsoft Windows 7

  1. Click Start -> All Programs -> Accessories.
  2. Right click “Notepad” and select “Run as administrator”
  3. Click Yes on the UAC prompt.
  4. Click File -> Open.
  5. Change the file filter drop down box from “Text Documents (*.txt)” to “All Files (*.*)”.
  6. Browse to “C:WindowsSystem32Driversetc”.
  7. Select “hosts” and click “Open”.
  8. Insert your Ecenica web servers IP and domain name. For example: 100.100.100.100 example.com.
  9. Close Notepad. Click Save when prompted.