To test and verify your server’s operation without modifying DNS records, you can add a domain entry to your local host file. This allows you to point a domain to a specific IP address on your local machine.
Here is how to do it:
For Windows:
- Open Notepad as an administrator. For this , Click on the Start menu, type ‘Notepad’, right-click on Notepad, and select Run as administrator.
- Open the hosts file:
In Notepad, go to File > Open.
Navigate to ‘C:\Windows\System32\drivers\etc’.
Select ‘All Files (*.*)’ from the file type dropdown.
Open the ‘hosts’ file. - Add the Domain Entry at the end of the file. add a new line with your server’s IP address, followed by the domain name.
For example:
192.168.1.100 example.com - Save the file and close Notepad.
- Clear DNS cache (optional but recommended). First , Open Command Prompt as an administrator. then, run below command –
‘ipconfig /flushdns’.
For macOS and Linux:
- Open the Terminal:
For macOS: Press Cmd + Space, type Terminal, and press Enter.
For Linux: Open your terminal application. - Edit the Hosts File:
Run the command:
sudo nano /etc/hosts
Enter your password if prompted. - Add the Domain Entry at the end of the file. Add a new line containing your server’s IP address, followed by the domain name.
For example:
192.168.1.100 example.comSave the file by pressing ‘Ctrl + O’, then press Enter to confirm.
Exit nano by pressing ‘Ctrl + X’. - Clear DNS cache (optional but recommended):
For macOS:
Run the command:
‘sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder’
For Linux:
The method varies by distribution, but you can often restart the DNS service or use a command like ‘sudo systemctl restart nscd‘ or ‘sudo systemd-resolve –flush-caches‘.
Verifying the changes:
- Open your preferred web browser.
- Type the domain name you added (e.g., ‘example.com’) into the address bar and press Enter.
- Check the Server Response. If the server is operating correctly, you should see your website or the server’s default page.
If not, verify that the IP address and domain name in your hosts file are correct and that your server is running.
By following these steps, you can confirm your server’s operation by locally pointing a domain to it without making any changes to external DNS records. This is especially useful for testing new servers, troubleshooting issues, or setting up a development environment.