How to edit the hosts file (Mac, Windows & Linux)


The hosts file is a text file that maps hostnames to IP addresses. Upon typing a url address on the browser, the system is checking if there is a relevant entry on the hosts file and gets the corresponding IP address, else it resolves the IP via the active connection’s DNS servers. The hosts file can be edited to block certain hostnames (like ad-serving/malicious hosts), or used for web development purposes, i.e. to redirect domains to local addresses.

The hosts file will look something like this:

### Host Database##
127.0.0.1 localhost
255.255.255.255 broadcasthost
95.211.13.120 www.domain.com

localhost is used to configure the loopback interface# when the system is booting. Do not change this entry.

Mac OSX

To edit the hosts file on mac os x you have to open the hosts file in Terminal. Please follow the steps below to do this.
  1. Open Terminal
  2. Run the following command: sudo nano /private/etc/hosts
  3. Enter your administrator password en press enter
  4. You now see a new screen where you can enter the details
  5. Press Ctrl + O to safe your modification
  6. Press Ctrl + X to close nano

Windows

If you want to change the hosts file on windows you have to change the hosts file with notepad in administrator mode. Please make sure you have administration right or able to run notepad as administrator.
  1. Go to Start -> All Programs -> Accessories
  2. Right click Notepad and select Run as administrator
  3. Accept to run the program as administrator if you see "Windows needs your permission".
  4. In Notepad opens Click File -> Open
  5. Type the following in the filename filed and click open. C:WindowsSystem32Driversetchosts

Linux

To edit the hosts file on Linux (ubuntu) you have to open the hosts file in Terminal. Please follow the steps below to do this.br/>
  1. Open Terminal
  2. Run the following command: sudo vim etc/hosts
  3. Enter your administrator password (if needed) en press enter
  4. You now see a new screen where you can enter the details
  5. Press Ctrl + O to safe your modification
  6. Press Ctrl + X to close nano