Method #1: Use the hosts file
Another method for bypassing DNS is to use the hosts file on your local computer. The hosts file contains domain name to IP address mappings. These mappings mimic the function of a DNS server, and allow you to “trick” your computer into associating a domain name with a particular IP address. To use the hosts file to bypass DNS for your domain, follow these steps:-
Open the hosts file in a text editor. The location of the hosts file depends on your computer’s operating system:
-
On Microsoft Windows computers, the hosts file is located at %SystemRoot%\system32\drivers\etc\hosts.
📘 Note
- On Windows Vista, Windows 7, and Windows 8, click Start, search for Notepad, right-click the icon, and select Run as Administrator.
-
On Windows 10, click Start, type
notepad, right-click Notepad, and then click Run as administrator.
This starts Notepad with the elevated privileges necessary to open, modify, and save the hosts file. Note that in Notepad’s Open dialog, you must use the All Files filter to see the hosts file.
-
On Apple Macintosh computers, the hosts file is located at /etc/hosts. For example, in a terminal window
typesudo nano /etc/hoststo open the file in a text editor with the correct permissions. - On Linux computers, the hosts file is located at /etc/hosts.
🚧 Important The hosts file is a plain text file, so you should use a plain text editor like Notepad or nano to edit it. Do not use a word processor like Microsoft Word, which can add additional formatting and cause more problems than it solves!
-
On Microsoft Windows computers, the hosts file is located at %SystemRoot%\system32\drivers\etc\hosts.
-
When you open the hosts file, you should see an entry that resembles the following line:
-
To create a new mapping for your domain, add the following line to the file:
-
Save the hosts file and exit the text editor. For example, if you are using the nano text editor, press Ctrl+O, press Enter, and then press Ctrl+X.
🚧 Important If you are using macOS, you should also clear the DNS cache. For information about how to do this, please see this article.
-
To test the configuration, restart your web browser and go to http://example.com or http://www.example.com, where_example.com_ represents your domain name. You should see your web site’s main page (assuming you have created some content).
🚧 Important After DNS propagation is complete, make sure you go back and remove the relevant entries from the hosts file!