Edit Hosts File on Windows Server 2019

Hello Devs, welcome to this journal article on editing the hosts file on Windows Server 2019. Hosts file is an important file that allows you to map a domain name to an IP address. In this article, we will guide you through the steps to edit the hosts file on Windows Server 2019.

What is Hosts File?

The hosts file is a plain text file used to map domain names to IP addresses. When you enter a domain name in your browser, your computer looks up the IP address associated with the domain name. This process is known as DNS (Domain Name System) lookup. The hosts file contains a list of domain names and their associated IP addresses. Editing the hosts file allows you to resolve domain names locally without relying on DNS servers.

Why Edit Hosts File on Windows Server 2019?

Editing the hosts file on Windows Server 2019 is useful in various situations such as:

  • Testing a website before transferring it to a live server
  • Accessing a website on a local network before it goes live
  • Blocking access to certain websites
  • Redirecting a domain name to a different IP address

How to Edit Hosts File on Windows Server 2019?

Here are the steps to edit the hosts file on Windows Server 2019:

Step 1: Open Notepad as Administrator

The hosts file is a system file that requires elevated privileges to edit. Therefore, you need to open Notepad as an administrator to edit the hosts file.

To open Notepad as an administrator, follow these steps:

  1. Right-click on the Notepad icon in the Start menu
  2. Select “Run as administrator”
  3. If prompted by User Account Control, click “Yes” to allow the program to make changes to your computer

Step 2: Open Hosts File

Once Notepad is open, you need to open the hosts file located in the system32 folder.

To open the hosts file, follow these steps:

  1. Click “File” in the top-left corner of the Notepad window
  2. Select “Open”
  3. In the “File name” field, type “C:\Windows\System32\drivers\etc\hosts”
  4. Click “Open”

Step 3: Edit Hosts File

After opening the hosts file, you can add, remove or modify entries as per your requirement.

The hosts file has a simple syntax. Each entry is a separate line that contains an IP address followed by one or more domain names separated by a space or tab. Here’s an example:

IP Address
Domain Names
192.168.0.10
example.com www.example.com

In the above example, the IP address “192.168.0.10” is mapped to two domain names “example.com” and “www.example.com”.

You can add your own entries to the hosts file. Make sure to save the file after making changes.

Frequently Asked Questions

Q. Can I block a website using the hosts file?

Yes, you can block a website using the hosts file. To do so, add an entry to the hosts file with the IP address “127.0.0.1” followed by the domain name you want to block. For example:

READ ALSO  Free Eco Server Hosting for Dev
IP Address
Domain Names
127.0.0.1
example.com www.example.com

In the above example, the domain names “example.com” and “www.example.com” are blocked and will not resolve to their actual IP addresses.

Q. Can I redirect a domain name using the hosts file?

Yes, you can redirect a domain name using the hosts file. To do so, add an entry to the hosts file with the IP address you want to redirect to followed by the domain name you want to redirect. For example:

IP Address
Domain Names
192.168.0.10
example.com www.example.com

In the above example, the domain names “example.com” and “www.example.com” are redirected to the IP address “192.168.0.10”.

Q. Can I edit the hosts file on a remote Windows Server 2019?

Yes, you can edit the hosts file on a remote Windows Server 2019 using a text editor such as Notepad++. However, you need to have administrative privileges on the remote server to edit the hosts file.

Q. Can I use wildcards in the hosts file?

No, you cannot use wildcards in the hosts file. Each entry should contain a specific domain name and its associated IP address.

Conclusion

Editing the hosts file on Windows Server 2019 is a simple process that can be useful in various situations. You can use it to test a website locally, block access to certain websites or redirect a domain name to a different IP address. We hope this article has helped you understand how to edit the hosts file on Windows Server 2019. If you have any questions or feedback, feel free to leave a comment below.