HomeMiscellaneousModifying your host file to override DNS of a domain

Modifying your host file to override DNS of a domain

This article will guide you on how to add an entry in your machine’s host file to lookup up the A record for a domain directly without DNS name resolution, this is commonly used for the testing website before changing the name server as it will override the DNS settings on that particular machine where you edit the host file. This is a good way to test a site before you have transferred the domain from your old server to the new server.

Windows

You need to open and edit the host file using notepad with administrator privilege.

Step1: Navigate to notepad
step2: Right-click notepad and select ” Run as administrator”
Step3: Open c:\Windows\System32\Drivers\etc\hosts
Step 4: Add the following entry.

IPaddress domain.com
IPaddress www.domain.com

for example:

89.237.107.170  veeble.org
89.237.107.170  www.veeble.org

In the above example, replace the domain name and IP address with your actual domain name and IP address.

Finally your host-file should look like.

# Copyright (c) 1993-2009 Microsoft Corp.

#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host

# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
89.237.107.170 veeble.org
89.237.107.170 www.veeble.org

Step 5: Save the file and access the website using your favorite web browser.

Linux

step1: Open the Linux terminal
step2: Open the host file using your favorite editor (here we use “nano editor”).

#sudo nano /etc/hosts

Enter the password

Step 3: Add the following lines into your host file.

IPaddress domain.com
IPaddress www.domain.com

for example:

89.237.107.170 veeble.org 
89.237.107.170 www.veeble.org

In the above example, replace the domain name and IP address with yours.

Step 4: Press control+X, then answer “y” to save the changes.

That’s it!
Go and access your website using any web browser!

Mac

Step1: Open Mac’s terminal
Step2: Open the host file by entering the following command on your terminal.

#sudo nano /private/etc/hosts

You are required to enter the Mac user's password and press return.

Step 3: Add the following entries to the bottom of your host file.

IPaddress domain.com
IPaddress www.domain.com

for example:

89.237.107.170 veeble.org
89.237.107.170 www.veeble.org

In the above example, replace the domain name and IP address with yours.

Step4: Save the changes by pressing control+o, then return to accept the filename.
Step5: Exit the editor by pressing control+x. You are now at the terminal screen.
Step6: Flush your Mac’s DNS cache by entering the following command.

#sudo dscacheutil -flushcache

Done!
Access the website in your browser and make sure everything is fine.

Note:- Please remove the entries when testing is complete.

Scroll to Top