modifying your hosts file - newicon

 

Modifying your hosts file allows you to override DNS settings on your local machine.  This is very useful if you are trying to test a site before switching over the global DNS you can do a dry run with just your machine.

Essentially by modifying your hosts file we get your machine to resolve the domain to the specific IP address.

So all we have to do is add the entries for the websites we want to resolve.  Lets say we have built our brand new website www.example.com and deployed to its brand new server on IP 11.11.11.11. Therefore to get our machine to go to 11.11.11.11 when we type in www.example.com we need to add the following line to our hosts file:

 

Windows

Windows 10, Windows 8, Windows 7, and Windows Vista use User Account Control (UAC), so Notepad must be run as Administrator.

For Windows 10 and 8

  1. Press the Windows key.
  2. Type Notepad in the search field.
  3. In the search results, right-click Notepad and select Run as administrator.
  4. From Notepad, open the following file: c:\Windows\System32\Drivers\etc\hosts
  5. Make the necessary changes to the file.
  6. Click File > Save to save your changes.

For Windows 7 and Vista

  1. Click Start > All Programs > Accessories.
  2. Right-click Notepad and select Run as administrator.
  3. Click Continue on the Windows needs your permission UAC window.
  4. When Notepad opens, click File > Open.
  5. In the File name field, type C:\Windows\System32\Drivers\etc\hosts.
  6. Click Open.
  7. Make the necessary changes to the file.
  8. Click File > Save to save your changes.

Windows NT, Windows 2000, and Windows XP

  1. Click Start > All Programs > Accessories > Notepad.
  2. Click File > Open.
  3. In the File name field, type C:\Windows\System32\Drivers\etc\hosts.
  4. Click Open.
  5. Make the necessary changes to the file.
  6. Click File > Save to save your changes.

Mac

Mac OS X 10.6 through 10.12

  1. Open Applications > Utilities > Terminal.
  2. Open the hosts file by typing the following line in the terminal window:
  3. Type your domain user password when prompted.
  4. Edit the hosts file. The file contains some comments (lines starting with the # symbol), and some default hostname mappings (for example, 127.0.0.1 – local host). Add your new mappings after the default mappings.
  5. Save the hosts file by pressing Control+x and answering y.
  6. Make your changes take effect by flushing the DNS cache with the following command:

    Or if this command does not work:

The new mappings should now take effect.

If you’re interested in working with Newicon on your next digital project, get in touch now.