Hosts File Mac

Hosts file mac os

  1. How To Add Host Entry On Mac
  2. Hosts File Mac
  3. Hosts File Macbook Locked
  4. Hosts File Macbook

The hosts file is used to map hostnames (in other words domains) to IP addresses. With the hosts file, you can change the IP address that you resolve a given domain name to. This change only affects your own computer without affecting how the domain is resolved worldwide. All Mac computers store a small, text based file called 'hosts'. Modifying this file is sometimes necessary to solve connection problems, set your own web server, and instruct the system to block access to specific websites (thus to prevent opening malicious websites). How to edit your Mac hosts file (Mac OS X) Sometimes you need to view a site on a development server. It’s something that I use regularly to connect to a development server using the regular site domain but mapped to a development server’s IP address.

Hosts

You may be wondering Where is the “Hosts” File on a MAC? The host file is located in the /private/etc/hosts on your MAC. Because it is situated in a protected area of the system, you cannot directly open the file and edit it. The solution is to copy the file to an unprotected location for example desktop and then make the modifications. The easiest way to find the host file is to use the Finder tool. When you have launched the Finder tool, you can select Go to Folder and enter the file location /private/etc/hosts. Now, you must select the “hosts” file with your mouse cursor and drag it to the desktop. Doing so will unlock the file and enable you to edit it.

Editing the Hosts File on a MAC

Hosts file mac

How To Add Host Entry On Mac

File

To edit the host file, you must first open it by double clicking it. You will notice that it is a simple file that contains just a few lines of text and characters such as pound and hash tags. The file also list the IP address of the localhost and broadcasthost. Before making changes on the hosts file, you should first backup the files. The hosts file can be backup by entering the hosts backup command in the terminal app. When making edits in the file, you cannot use mouse click as the mouse has been disabled in the text editor. Instead, you are to use the arrow keys to travel to different lines.

Blocking Access to Certain Websites with the Hosts File

For some people, they edit the host file in order to block the user from accessing a certain site on the Mac system. If you want to block access to a specific website, you must map the particular website you want to block to an invalid IP address such as 0.0.0.0 so that the browser won’t be able to display the page when someone tries to enter the URL.

Enter the Redirected URLs into the Hosts File

If you don’t want to redirect the website to an invalid IP address, you can enter the valid IP address of the site where you want the user to be redirected. In this way, the user will be redirected to a different site when he attempts to visit the site with the browser. You can find out the IP address of a website by sending a ping to the site via the Terminal. You must quickly record down the returned IP address on a text editor so that you won’t enter the wrong number into the file.

The entry should be entered in the format of the IP address followed by a space and then domain name. There is no limit as to how many entries of IP addresses you can enter into the host file. Every line should have only one entry. It is advised that you don’t delete the entries previously entered as they are required to be processed by the system when it is booting. As soon as you have entered a new entry, you should press Control + O key to confirm that you want the modifications on the file to be applied to the original version in /private/etc/hosts/.

Mac host file path

Hosts File Mac

Testing the Hosts File to See if it Works Properly

Hosts File Macbook Locked

After you have finished making the modifications, you must copy and paste the hosts file back to the original location. There will be a prompt that ask you whether you want to replace the file. To authenticate the file replacement, you must enter your administrative password. After the file is replaced, you can enter the URL in your browser to see whether the changes have been effected. You may have to delete the existing DNS cache in order for the effect to take place. To delete the existing DNS cache, you can enter the syntax dscacheutil -flushcache into the terminal.

Hosts File Macbook

Conclusion

In conclusion, it is very easy to locate the hosts file and make edits to control the sites other users will see. You can try turning off your computer and restart the system again if the website did not display properly after you followed the steps above. Sometimes, you need to quit all open browsers in order for the changes to take effect.