Host File Windows Server 2019: The Ultimate Guide for Devs

Hello Devs, if you are someone who manages a Windows Server 2019 or your organization is planning to switch to it, then you must have heard of the host file. Host file is one of the vital components of a server that you must pay attention to. In this article, we will walk you through everything you need to know about host file in Windows Server 2019. We will cover from the basic concept, how to modify it, and how to troubleshoot common issues. Keep reading to become a host file pro!

What is Host File in Windows Server 2019?

Before we dive deeper into what host file in Windows Server 2019 is, let’s start with the fundamental question. What is a host file?

In its simplest form, a host file is a plain text file that maps IP addresses to domain names. It acts as a local DNS resolver that can override the system’s default DNS settings. By editing host files, you can control which IP address a domain name should point to. Host files are useful when you want to test a website without changing the domain’s DNS settings or accessing an internal network that is not publicly accessible.

In Windows Server 2019, the host file is located in the %SystemRoot%\system32\drivers\etc directory. By default, the host file only contains the localhost loopback address (127.0.0.1) and the local host name (localhost).

How to Modify Host File in Windows Server 2019

Now that you understand what host file is, how do you modify it in Windows Server 2019? There are several ways to do it.

Using Notepad

The easiest and most common way to modify the host file is by using Notepad. Here are the steps:

  1. Open Notepad as an administrator.
  2. Click File and then Open.
  3. Navigate to the %SystemRoot%\system32\drivers\etc directory.
  4. Change the file type to All Files.
  5. Double-click on the hosts file.
  6. Add the IP address and domain name in the following format: IP address domain name.
  7. Save the file.

Using Command Prompt

Another way to modify the host file is by using Command Prompt. Here are the steps:

  1. Open Command Prompt as an administrator.
  2. Type “notepad %systemroot%\system32\drivers\etc\hosts” and hit Enter.
  3. Add the IP address and domain name in the following format: IP address domain name.
  4. Save the file.

Host File Examples for Windows Server 2019

To give you a better understanding, here are some common examples of host file entries that you can use in Windows Server 2019:

Mapping a Domain to a Local IP Address

Let’s say you have a website hosted on a local server with the IP address of 192.168.1.100. To access the website from other devices on the same network, you can add the following entry to the host file:

IP Address
Domain Name
192.168.1.100
yourwebsite.com

After adding this entry to the host file, you should be able to access the website by typing “yourwebsite.com” in the browser’s address bar.

Blocking a Domain

You can also use host files to block access to a website from your network. Here is an example of how to block Facebook:

READ ALSO  SQL Server C# Connection: A Comprehensive Guide for Dev
IP Address
Domain Name
0.0.0.0
facebook.com

After adding this entry to the host file, any attempt to access Facebook will redirect to a blank page.

Troubleshooting Common Host File Issues in Windows Server 2019

While host files can be handy, they can also cause issues if not configured correctly. Here are some common host file issues and how to troubleshoot them:

Host File Not Working

If your host file changes are not taking effect, try flushing the DNS cache. Here are the steps:

  1. Open Command Prompt as an administrator.
  2. Type “ipconfig /flushdns” and hit Enter.
  3. Restart your web browser.

Host File Syntax Error

If your host file contains a syntax error, it can cause issues with DNS resolution. To fix this, open the host file and check for any typos or missing characters.

Frequently Asked Questions (FAQ)

What is the Hosts file used for?

The host file is used to map IP addresses to domain names. It acts as a local DNS resolver that can override the system’s default DNS settings.

Where is the Hosts file located in Windows Server 2019?

The host file in Windows Server 2019 is located in the %SystemRoot%\system32\drivers\etc directory.

How do I edit the Hosts file in Windows Server 2019?

You can edit the host file in Windows Server 2019 by using Notepad or Command Prompt as an administrator.

How do I troubleshoot Hosts file issues?

To troubleshoot Hosts file issues, you can flush the DNS cache, check for syntax errors, and ensure that the entries are correctly formatted.

And that’s a wrap! Congratulations, Devs, you have learned everything you need to know about host file in Windows Server 2019. Remember to use host files responsibly and keep them well-maintained. Happy networking!