Modifying Hosts file in Windows

This file is used to associate names with IP addresses.
Usually we use DNS Server as a name service, but sometimes we want to associate a custom name to a concrete IP address.

Priority over DNS

Hosts configured in hosts file will go first, in fact, DNS won’t be queried if an entry is found in hosts file.

Adding hosts to hosts file

Open an elevated command prompt and execute:

notepad %windir%\system32\drivers\etc\hosts

Hosts file will be opened in notepad.
Add a host this way:
IP NAME
For example, we can add the following at the end of the hosts file:

192.168.0.56 printer
192.168.0.66 webmine

We save & close notepad as usual.
We can check this config by pinging the new host, just open a command prompt and write:

ping printer

We will see that the host is resolved, in this case with theĀ  192.168.0.56 IP address.

Leave a Reply

Your email address will not be published. Required fields are marked *