Temporarily force your machine to resolve to the correct DNS Print

  • 0

Temporarily force your machine to resolve to the correct DNS.

Precaution: This is for testing and troubleshooting purposes only and it is best left for windows or linux to manage this file properly. Unless you are an admin and know what you are doing, you may proceed.


You can force your windows or linux machine to redirect to the correct DNS or IP by following the steps below. Please change the IP and domain examples to your own.


Windows
Find the local host file by using your windows explorer and browsing through: 
C:\Windows\System32\drivers\etc\hosts

You can edit this file in Notepad with administrator privileges.

Linux

The Linux hosts file is found here:

/etc/hosts
You can edit this file in a text editor with root privileges.

Follow the formatting stated below:

Example

7.7.7.7 new.domain.com

Once you save the file, it will load the new entries and reflect in your DNS cache. No need to restart the machine.

To show that this is loaded instantly into the DNS cache, run the following command to clear all DNS cache on the local machine – you may need administrative privileges.

ipconfig /flushdns

After this, run the next command which should display all DNS entries.

ipconfig /displaydns

After this you should see your host file entries cached.


Windows IP Configuration

testing.test123.com
----------------------------------------
No records of type AAAA

new.domain.com
----------------------------------------
Record Name . . . . . : new.domain.com
Record Type . . . . . : 1
Time To Live . . . . : 86400
Data Length . . . . . : 4
Section . . . . . . . : Answer
A (Host) Record . . . : 7.7.7.7

Assuming there is a web server at 7.7.7.7, you could now load http://new.domain.com in a browser and it would load the website hosted there for this website. You could also try to ping your domain name and it should resolve to the IP address correctly.

The hosts file can be used to make your local machine resolve any DNS record that you like, it does not have to exist externally. This is great for troubleshooting, especially for web developers as you could simply point test.domain.com to your web server and then load this in a browser to see the content without having to gain access to the DNS zone.


Was this answer helpful?

« Back