How to Point a Domain to a Server in Local System for Testing Websites?

Posted on October 24th, 2018

How to Point a Domain to a Server in Local System for Testing Websites?

If you are creating a website in the new server before updating nameservers at your domain registrar end, you can point that domain to a new server in your local system via the hosts file. When you call a website in a browser, the system first checks your hosts file entries for that domain. If there is no entry for that domain, the system will go to DNS root servers to find that domain hosted server. If your nameservers are not updated, you will get a page like below screenshot.

Point Domain

 

Consider the scenario you have migrated your website from old host to the new host and the website is still resolving to the old server and you want to test your website is working or not. In this situation, you can point your website to your new server in your local system. Assume your new server IP is 192.168.1.10 and domain name is example.com. You can add below entry in your hosts file to point website to the new server.

Open your hosts file then add:

192.168.1.10   example.com

Then save the file. You can confirm the domain is resolving to the new server in your local system by ping domain name.

Open your Terminal or Command prompt and run below command.

ping example.com

In this case, you will get below result.

Pinging example.com [192.168.1.10] with 32 bytes of data

In this tutorial, I will show how to edit hosts file in Windows, Mac, and Linux.

 

Windows

If you are using Windows Operating System, the hosts file location is C:\Windows\System32\Drivers\etc\

Point Domain

 

From there you can access the hosts file.

Open with a text editor and add a new entry at the end of the file.

xxx.xxx.xxx.xxx.xxx   domainname .com

Then save the file.

 

Mac

If you are using Mac OS, the hosts file location is /private/etc/hosts

Open your terminal to access hosts file and run below command to edit hosts file.

sudo nano /private/etc/hosts

 

Linux

If you are using Red Hat based OS, the hosts file location is /etc/hosts

Open your terminal and switch to root user to access hosts file and run below command.

vim /etc/hosts

If you are using Debian based OS open terminal and run below command to edit the hosts file.

sudo vim /etc/hosts

 

If you need any further assistance please contact our support department.

 

 

5 Responses to “How to Point a Domain to a Server in Local System for Testing Websites?”

  1. Jerry Peres says:

    The post you shared here is very informative. Thanks for publishing such a nice and great post here.

  2. Sheen Sabu says:

    Can you help me with this topic.The information you given above was not much heipful. I need information about how can we point a website we hosted to a server.It would be more helpfull if you can provide help in this topic in case of a server in docker container.

  3. Daryl Shull says:

    If I understand this right… my godaddy.com website name where I purchased can be pointed to my hosted server at home? I run a server at home for family. so I am only using numbers. IP numbers. I want my example.com to point to my home server..

    • Adding in local host will work for the specific PC only. Once added, you can access the website via browser (for your PC only). For public access, you need a public IP.

  4. Abubakar Yahya Muktar says:

    This post very helpfulness 🙏

Leave a Reply