How to change DNS using hosts file

Last updated on April 24th, 2017 at 12:10 pm

cover - How to change DNS using hosts file
When you want to verify a test domain or alias, before to take effect of online changes, you can try to change DNS. Learn how to change DNS using hosts file.
Modifying the hosts file makes sure that the local computer directly points to specified IP address.

 

Hosts file structure is very simple
<ip-address> <domain.name>

 

Example of file host

10.1.1.200 www.testdomain.com
10.1.1.200 testdomain.com

In this case all the host calls www.testdomain.com or testdomain.com will point to IP 10.1.1.200

 

HOW TO CHANGE DNS USING HOSTS FILE IN WINDOWS

IThe hosts file on Windows operating systems is located in C:\Windows\System32\drivers\etc\hosts, to change it you need Administrator rights, then open it with your favorite text editor.

How to change DNS using hosts file - locate hosts file in windows

 

 

 

Windows NT, Windows 2000 e Windows XP

  • From the Start menu > All Programs > Accessories > Notepad
  • Click File > Open
  • In the File Name field, type C:\Windows\System32\drivers\etc\hosts
  • Click to Open
  • Make the necessary changes to the file
  • Click File > Save to save the changes

 

Windows 7 e Vista

  1. From the menu Start > All Programs > Accessories
  2. Click Notepad and click Run as Administrator
  3. Click Continue to agree permission
  4. When Notepad opens, click File > Open
  5. In the File Name field, type C:\Windows\System32\drivers\etc\hosts
  6. Click Open
  7. Make the necessary changes to the file
  8. Click File > Save to save the changes

 

Windows 10 e 8

  1. Press the Windows key
  2. Type notepad in the search field
  3. In the search results, click the right mouse button Notepad and click Run as Administrator
  4. When Notepad opens, click File > Open
  5. In the File Name field, type C:\Windows\System32\drivers\etc\hosts
  6. Make the necessary changes to the file
  7. Click File > Save to save the changes

 

HOW TO CHANGE DNS USING HOSTS FILE IN LINUX

  1. Open a terminal window
  2. Open the hosts file in a text editor (use your favorite text editor) by typing sudo vi/etc/hosts
  3. Enter the password
  4. Make the necessary changes to the file
  5. Type :wq
  6. When asked if you want to save the changes, answer y

locate hosts file in linux

 

 

Hosts file usually contains some comments (lines beginning with the # symbol), and some default mappings (for example, 127.0.0.1 – localhost).
Add your new mappings after the default mappings, made the changes to restore the previous mappings, yuo can use # to comment on them.

 

 

WikiRails Team

Staff WikiRails