Hosts charge is an significant file located in your macintosh allows mapping IP addresses to host names. The IP map controls the browser, how the locate cover entered should be handled before it goes to browser ’ randomness DNS resoluteness. There are two chief reasons one should think of adding map in hosts file :

  1. To directly map the domain to an IP so that the resolution time is fast.
  2. To block domains by defaulting it to localhost IP.

In this article we discuss how to edit hosts file in macintosh OS X with Yosemite version 10.10.2 .

Edit Hosts File in Mac OS X

Hosts file is located in the file path “ /private/etc/hosts ” in macintosh. You should have an administrator privileges in holy order to edit the hosts file. Press “ Command + Space ” buttons in the keyboard to open “ Spotlight Search ”. Enter “ Terminal ” and bivalent click on the “ Terminal ” app appearing as a top hit.

You can besides open Terminal from the path “ /Applications/Utilities/ ” through Finder .

Backing up Hosts File

It is always a dear mind to backup things before you start modifying. Type the downstairs command in the Terminal command prompt and press enter to backup your hosts file to the Documents folder .
sudo cp /private/etc/hosts ~/Documents/hosts-backup You will see a warn message and ask you to enter system password to proceed farther. Type your password, you will not be able to view the password when type, so wear ’ triiodothyronine get panic that you are not able to type the password in Terminal app. Press accede after typing the password and check in the Documents folder to find the UNIX feasible backup charge named “ hosts-backup ” .
Hosts file in macintosh is located in the path “ /private/etc/hosts/ ”, open the hosts file by typing the below command in Terminal and type the admin password .
sudo nano /private/etc/hosts Hosts file will be loaded in nano editor program and practice arrow marks to reach the last production line where you can enter modern IP and knowledge domain name. For exercise, you can map this site www.webnots.com with an IP 74.220.193.173 so that whenever you open the web site hosts file entry is used to map the IP promptly and the save time on resolving host name .

  • Leave a space between IP and domain name.
  • Enter one entry per line.
  • Don’t delete the previous entries available in the hosts file which are required for system booting.
  • Mouse click will not work in nano editor and you need to use arrow keys to go to the last line.
  • Type domain name without www and with www in two separate lines to consider both the entries. Here the IP address might be same.

once you added the necessitate entries, bid “ Control + O ” keys and bid enter / return identify to confirm the modification to the file “ /private/etc/hosts/ ”. Press “ Control + X ” to quit the nano editor program.

now the master of ceremonies file is modified but you may need to flush out the existing DNS hoard for the entries to be effective in the browser. Type the under instruction in Terminal and press record to flush out existing DNS entries .
dscacheutil -flushcache Open the site you maintained in hosts file in Safari and see how flying it gets loaded compared to ahead. If you use Chrome you will never see the embarrassing “ Resolving host… ” message in Chrome status browning automatic rifle any more .
Sometimes you may besides need to close all browser windows or restart the system for the changes to be effective. Did some mistake in modifying the hosts file ? Don ’ thymine concern just restore the accompaniment file saved in the Documents folders by typing the below dominate in Terminal app .
sudo cp ~/Documents/hosts-backup /private/etc/hosts

Blocking Domains Using Hosts File

If you want to block domains using hosts charge then the elementary way is to point those domains to the localhost IP address. The localhost IP is referred as : :1 for IPv6 and 127.0.0.1 for IPv4 hence add the under lines in hosts file to block a web site .
127.0.0.1 blocked-site.com

: :1 blocked-site.com

Leave a Reply

Your email address will not be published.