How to edit the hosts file on Windows Server 2016

Published: May 27, 2018 (Updated: May 27, 2018)

Enjoying this content? Subscribe to the Channel!

Mastering the Hosts File: A Step-by-Step Guide for Windows 10 and Server 2016

Welcome back to Darren’s Tech Tutorials!

The Hosts file is one of the oldest and most useful tools in the Windows operating system. It acts as a local address book, allowing you to manually map IP addresses to hostnames before your machine even bothers checking a DNS server.

Whether you need to test a new website locally, redirect a domain name for development purposes, or even block access to specific sites, understanding how to edit this file is essential.

In this comprehensive guide, we’ll walk through the process of locating, editing, saving, and testing the Hosts file on Windows. While we focus specifically on Windows Server 2016, these steps are nearly identical for Windows 10 and Windows 11 users!


What is the Hosts File and Why Do I Need to Edit It?

Before the internet relied heavily on DNS servers, computers used the Hosts file to translate names (like google.com) into numerical IP addresses. While DNS now handles global resolution, the Hosts file still takes precedence.

Any entry you make in the Hosts file is checked before your system queries a DNS server. This means you can:

  1. Test Local Development: Point a live domain name to a local IP address (like 127.0.0.1) to test changes before deployment.
  2. Block Websites: Redirect unwanted websites to a non-existent local address, effectively blocking them.
  3. Speed Up Resolution: For frequently accessed local resources, a Hosts entry can resolve the name instantly.

Step 1: Locating the Hosts File

The Hosts file is a critical system file, which means it’s buried deep within the Windows system directories.

To find it, navigate to the following path in File Explorer:

C:\Windows\System32\drivers\etc\

Inside the etc folder, you will find several networking configuration files. The one you are looking for is simply named hosts (it usually has no file extension).

Step 2: Gaining Administrator Permissions

Because the Hosts file is located within the highly protected System32 directory, you cannot simply double-click and save your changes. You must open your text editor (like Notepad) with elevated Administrator privileges, or Windows will deny your ability to save the modifications.

Here is the most reliable way to open and edit the file:

  1. Search for Notepad: Click the Start menu (or search bar) and type “Notepad.”
  2. Run as Administrator: Right-click on the Notepad application in the search results and select Run as administrator.
  3. Open the Hosts File: Once Notepad is open, go to File > Open.
  4. Navigate to the Location: Browse to the directory found in Step 1: C:\Windows\System32\drivers\etc\
  5. Change View: Crucially, Notepad defaults to showing only .txt files. In the bottom right corner of the Open dialogue box, change the dropdown menu from “Text Documents (*.txt)” to “All Files (*.*)”.
  6. Select hosts: The hosts file will now appear. Select it and click Open.

Step 3: Editing and Adding a New Host Entry

Now that the Hosts file is open, you can begin adding your custom mappings.

The format is simple: you must list the IP address first, followed by at least one space or tab, and then the hostname.

Format:

[IP Address] [Hostname]

Example:

Scroll to the bottom of the file (leaving any existing lines intact—especially the line starting with # 127.0.0.1 localhost).

Let’s imagine we want to map the hostname mynewtestserver to the local IP address 192.168.1.100. You would add the following entry on a new line:

192.168.1.100 mynewtestserver

Pro Tip: Comments

You can use the hash symbol (#) at the beginning of a line to add comments or temporarily disable an entry. This is extremely helpful for organizing your modifications.

# This is a comment explaining the entry below
192.168.1.100 mynewtestserver # Mapping for local development

Step 4: Saving and Exiting

After adding your necessary IP and hostname entries, you must save the file.

  1. Go to File > Save within Notepad.
  2. Since you opened Notepad as Administrator, the save operation should succeed instantly without prompting you to select a new location or file type.
  3. Close Notepad.

If you encounter an “Access Denied” error, double-check that you completed Step 2 correctly and ran the editor as administrator.

Step 5: Testing Your Changes

The final step is to verify that your system is successfully recognizing the new hostname mapping. We will use the built-in ping utility from the Command Prompt.

  1. Open Command Prompt: Search for cmd in the Start menu. You do not need to run this as Administrator.
  2. Run the Ping Test: Use the ping command followed by the hostname you just added.

If we use the example from Step 3:

ping mynewtestserver

Successful Outcome:

If your Hosts file edit was successful, the ping command will resolve the hostname to the IP address you specified in the file (192.168.1.100) and the ping packets will be sent to that address.

Unsuccessful Outcome:

If the ping resolves the name to a different IP address, or reports that the hostname cannot be found, the Hosts file edit failed. You may need to check the file for typos or ensure you saved the changes correctly.


Conclusion: Take Control of Your Network Resolution!

That’s all there is to it! Editing the Hosts file is a fundamental skill for network administrators, developers, and anyone who wants granular control over how their local machine resolves domain names. It’s a powerful, straightforward tool hiding in plain sight.

Give this tutorial a try and experience the power of local DNS resolution!

If this guide helped you master this tricky configuration file, be sure to drop a comment below letting us know what you’re using your Hosts file edits for. And as always, hit that Like button and Subscribe to Darren’s Tech Tutorials for more clear, practical technology deep dives!