There are many reasons why people attempt to edit the host file on their computers. In some cases, there can be an attack on the website and editing the host files will allow you to control access to the site in a better manner. You can also manage your network traffic efficiently and block certain traffic that looks suspicious. Other than that, it is also very effective when users have to test something in their website without using a test link. This can be done even before you go live with SSL. When you modify the host file, the local machine will directly go to the IP address as specified by the user, so you change DNS locally.
How to edit host file (DNS) in Windows?
Windows XP, 2000 and NT:
- To begin with, go to the Start button.
- From here, go to All Programs option.
- Select Accessories and further select Notepad.
- Once you start working on Notepad, select File option on left hand top side.
- Click the “Open” tab, enter file name as
- Here, you can make any modifications to the file locally.
- Click on save button to retain all the changes.
For Vista & Windows 7:
- Go to the Start menu located on the left side bottom of the desktop.
- Go to All Programs tab and select Accessories.
- Here, select Notepad and right click on that tab.
- Choose the “Run as Administrator” option given in the selection.
- Click on Continue tab when Windows will ask permission for UAC window.
- Now, Click File tab on Notepad and then proceed to click on Open.
- After that in that tab, type C:\Windows\System32\Drivers\etc\hosts
- Click on the tab and make required modifications to the File.
- Select File option and save the changes.
Windows 8 and 10:
- Locate the Windows key on the keyboard and press it.
- In the search box, type Notepad and hit Enter.
- Right click on Notepad tab and select the “Run as administrator” option.
- Click on File and select “Open” tab.
- Enter the file C:\Windows\System32\Drivers\etc\hosts
- Here you can make the required modifications.
- Select the file tab and save the changes made.
How to edit host file (DNS) in OS X?
Mac OS X 10.0 with 10.1.5
- To begin with, go to the Applications tab and Select Utilities.
- From here, you can go to the Netinfo Manager.
- You will have to click the padlock to edit the Netinfo database. This is very essential to complete the task.
- Now, you can enter the user password for the domain and click on the OK tab.
- In the browser’s next column, find the node which is named “Machines”.
- In the 3rd column, there will be three options.
- The three entries are broadcast host, DHCP and localhost.
- You have to select the localhost option.
- After this, you can go to “Edit” menu and select “Duplicate”.
- Remember that this is the easy method as you can create a fresh entry by duplicating the existing one.
- You will get an alert about this task.
- Select Duplicate and a fresh entry for localhost copy will appear.
- The properties of this new entry will be displayed on screen.
- You can double click on the “value of IP address” & enter “IP address” of the other system.
- In a similar manner, you can enter the hostname of the other system by double clicking on the “value of name” property.
- Now, it is time to open the “serves property” & choose the Delete option from “Edit” menu.
- You can now go to File menu and save the changes made.
- An alert will appear on the screen.
- You can now click on Update the copy.
- Remember that whenever you need to add a host entry, you will have to repeat the above process of duplicating the entries.
- The process is now complete and you can now select Quit option from “Netinfo Manager”.
- Unlike other systems, there is no need to restart system for the changes to be saved.
Mac OS X 10.6 with 10.11:
- It is similar to the other versions of Mac OS but varies slightly.
- Select the Applications tab and open it.
- Go to Utilities and choose the Terminal option.
- By typing the command in the terminal window you can open hosts file.
- Command “sudo nano /private/etc/hosts”
- Enter the “user password for domain” whenever it is asked by the system.
- Now, it is time to modify hosts file.
- Remember that the file will have some comments that begin with #symbol & other default hostname mappings.
- You have to add new mappings after default mappings.
- Now, you can save the hosts file by Control X tab together.
- When the window asks for confirmation, answer “y”.
- It is now time to flush DNS cache and save the changes by using the command given below.
- “dscacheutil –flushcache”
- This will enable new mappings to take effect.
How to edit host file (DNS) in Ubuntu?
In the case of Ubuntu OS and other Linux based OS, you can easily edit the hosts in the terminal. While some people prefer to use the GUI text editor, few others will open the VIM editor. The hosts file of Ubuntu will be located in the “/etc/folder”. As this is the root of the drive in some cases, you will need to open it as the root and this is the reason, you have to use “sudo” in the commands.
- Enter the command “sudo nano /etc/hosts”
- Enter the “domain user password” and make the necessary modifications to the file.
- Press Control-x and answer “y” whenever you want to save the changes.
This is the simple procedure to edit host file and change the DNS locally in Windows, Mac and Ubuntu OS.