How to edit hosts file mac terminal

The Mac OS X hosts file

You will now return to the main Terminal prompt. For the new settings to take effect you will have to flush your DNS cache. To accomplish this, enter the following command at the Terminal prompt:.

We're all over the place (socially speaking).

If an item is checked, it's stored in the hosts file, if it's unchecked, it's removed rather than commented out, but continues to be stored in the preference panel for future use. Remember to start every new entry from the new line and separate domain name from IP-address with at least one spacebar or Tab. Open one either by clicking on Applications , then Utilities and then Terminal , or by pressing Cmd-Spacebar to open Spotlight , typing Terminal and pressing Return. Best to stick to nano instead :D. The Terminal window should look like this: 2. November 6, at am.

Press Return. You can now close the Terminal window and your edits to the host mappings will take effect. From time to time you may find that you need to view a website that is hosted locally. Terminal will now ask you to enter your Administrator Password: Enter Password and then press Return 4.

Popular Topics

The hosts file will display in the Terminal window: To move throughout the hosts file, use your arrow keys to move up and down. This will bring up a prompt for the file name to write to: 7.

To accomplish this, enter the following command at the Terminal prompt: dscacheutil -flushcache Press Return. Now, whenever we try to go to www. Alternatively, you can enter the IP address of a valid site instead of 0.

For example, The New York Times website at www. You can add as many entries to the hosts file as you wish by entering new mappings on each line.

We're all over the place (socially speaking).

To flush the DNS cache on your Mac, open Terminal and use the following command sudo enables you to run this command as the admin of your machine :. The steps in the previous section are easy enough, but if you want to avoid copying the hosts file you can edit it directly in Terminal using the UNIX Nano Text Editor, which is built into macOS. To get started, launch Terminal, type the following command, and press Return.

How to Edit Hosts File on Your Mac Computer

To navigate and edit the file, use the arrow keys on your keyboard. Just as we did with the TextEdit method, above, we can add, edit, or remove hostname mappings at will. Because we launched Nano using sudo, any changes will be authenticated and saved directly to the original hosts file, without the need to copy it outside of its home directory.

Our examples mentioned blocking and redirecting distracting sites in a work environment. You can also use these steps to manually block access to malicious websites or, of course, to play a prank on friends and family members. Do not change this entry.