1. Home
  2. References
  3. Technical Advice
  4. How to modify your OS’ “hosts” file

How to modify your OS’ “hosts” file

Introduction

The “hosts” file is used to configure domain names  (hosts) from your computer directly and avoid the “domain resolution” process from a standard DNS query. With the hosts file, you can choose where  (on what IP address) your domain resolves to.

Often used during migrations of websites, this tip is very convenient when you want to preview and diagnose your website on a different server without touching the DNS entries which were already configured.

Hence why the changes made on your computer’s hosts file are local to your machine and will not affect other computers or users.

Locate the hosts file

The “Hosts” file location varies, depending on which Operating system is installed on your personal computer:

  • Windows 95/98/Me c:\windows\hosts
  • Windows 8 c:\windows\system32\drivers\etc\hosts
  • Windows 10 c:\windows\system32\drivers\etc\hosts
  • Linux /etc/hostss
  • Mac OS X /etc/hosts

How do I configure my Hosts file?

As an example If you want to your “domain.example” to resolve at address  1.2.3.4 you should open your “hosts” file with a text editor and add the following line:

1.2.3.4 domain.example www.domain.example

Once this line has been saved in your hosts file it will tell your computer to reach directly the page at 1.2.3.4   and avoid passing a typical “DNS resolve” query onto your internet service provider.

After having saved my “Hosts” file it does not work!

The changes are only taken into effect when all the caches are empty this includes the following:  Web browser(s) or the Operating system’s own DNS cache for the changes made in your hosts file to take effect.

For Windows:

Launch a CMD window with administrator privileges  and type the following command at prompt:

ipconfig /flushdns

For Mac launch the “terminal” from finder and type the following command at prompt:

dscacheutil -flushcache
Updated on 18 August 2021

Was this article helpful?

Related Articles