How to point a domain to a server using hosts file in Windows?

You are here:
  • Main
  • DNS
  • How to point a domain to a server using hosts file in Windows?
← All Topics
Table of Contents

If you need to quickly point a domain name to a server, but do not want to change the nameserver of the domain, then you can do that with the windows hosts file. The hosts file is a local zone record where you can modify or add a record for domains that will immediately work on your computer.
For example, if your domain is currently pointed to another hosting provider, and you are migrating the website to IT Nut Hosting. You might not want to change the nameserver of the domain yet until you have finished the website migration.

So, if you want to change the DNS record of that domain to point to the new server only for yourself, you can use the hosts” file. The rest of the world will still visit your website and be taken to the previous hosting provider. You will need to know the IP address of the server where you want to point the domain. You will receive the IP address for your hosting server once your hosting order is confirmed. To modify the “hosts” file, follow the instructions:

  1. Go to “C:\Windows\System32\drivers\etc” and copy the “hosts” file from there to your Desktop.
    Hosts file in File Manager
  2. Open that file with “Notepad” text editor from the desktop.
    Open With Notepad
  3. You will see some descriptions on that file. If you see the # symbol on the beginning of a line, that is a comment and is not any type of command. Go to the bottom of that file and enter the server IP address on a new line.
  4. Press the “Tab” button on your keyboard twice to create some space, then enter the domain name.
  5. Press enter to create another new line, enter the same IP address, press tab twice and this time, enter the domain name with www. at the beginning of it.
    Edit Hosts File
  6. Now save the file from “File” > “Save”
  7. Now copy this “hosts” file from Desktop and paste it to “C:\Windows\System32\drivers\etc” folder
  8. When prompted to replace the existing “hosts” file, click on the “Replace the file in the destination” button. After that, click on the “Continue” button when prompted for Administrator permission as the ‘hosts’ file is a system file.

Once you have done that, you can now visit that domain, and you will be taken to the IP address that you have specified.

You can easily reverse the changes by opening that hosts file from Desktop, put “#” symbol at the beginning of those two lines or remove them altogether. Then save the file and copy it to “C:\Windows\System32\drivers\etc” folder as before.

Just like that, you have successfully pointed your domain to a server and once the work is done, you have also reversed the changes.

Was this article helpful?
0 out of 5 stars
5 Stars 0%
4 Stars 0%
3 Stars 0%
2 Stars 0%
1 Stars 0%
How can we improve this article?
Tags: