Teach your Mac OS system four ways to change the Hosts file

Source: Internet
Author: User

users who are using Mac OS x systems. At some point, you may encounter the need to change the system Hosts file, how does Mac OS system change the Hosts file? What's the difference between a Windows system? We know the fact that changing the hosts file only requires that the file be found on the hard disk, and then editing the changes is OK. But very many children's shoes found that only to edit the Hosts file will appear "You are not the file hosts all the people, so there is no permission to write to the file" prompt, to solve this permission problem is more troublesome, for the users just use MAC is not easy to clear.

So. We are here to collect and collate the following methods for everyone to use, hoping to help everyone.

1. Change through VI Editor

Open Terminal (Application--useful tool), execute:

sudo vi/etc/hosts

You will be prompted to enter password (no matter what characters are displayed when you enter password). Do not even show, press ENTER after you have finished the Hosts file, press I to enter insert mode (which can be understood as edit mode), and then edit the file as you need it. Press ESC to exit Insert mode when you are finished editing. Then press: wq+ Enter to save exit. Remember that the colon in English is also to be entered OH.

The VI editor should not be unfamiliar to users who often use Linux. And the editor is built into the MAC system by default.

But. For users who have not used VI. It really takes a while to learn its basic usage. In addition VI editor is a very good very powerful tool, want to play good Mac words. It is best to master the use of this tool.

2. Use the Nano Editor to change

Similar to the above method, this editor is more easy to use than VI, but the function is not strong, it seems that there is no VI popular. The same method is performed in the terminal:

sudo nano/etc/hosts

The same is the input password. Open the Hosts file and edit the file according to your needs, and then press Ctrl+o to save it. When the File Name to Write:/etc/hosts, press ENTER to confirm, and then press Ctrl+x to exit.

3. Merging files with cat commands

This method is more appropriate when you want to add some content to the Hosts file. First, you need to add the content that needs to be added to the Hosts file as a txt text file (recommended to be saved directly in your user folder). Here I take the 123.txt saved in the user folder as an example.

The same is to start the terminal, and then execute the following two commands:

Sudo-s

Cat ~/123.txt/etc/hosts

~ Symbols on Mac and even all Unix and Linux-based systems are user folders representing the current User: represents the current folder. This time you should be clear on why the above command is ~/123.txt.

4, directly in the graphical interface changes

Open Finder. Then click on the menu bar to go-to the directory (or shortcut key shift+command+g), enter/private in the path, after entering in the ETC directory right click-show a simple introduction, in the table of contents simple Introduction to find "Sharing and permissions", will Everyone's permission changes to "Read and write", if you find that can not be changed, the lower right corner of the small lock can be changed.

After changing the permissions of the ETC directory, enter the ETC directory below. Change the permissions named Hosts file (same as everyone read and write), after the change is complete. You will be able to right-click on the Hosts file and open and edit the file via text edit. No prompt will appear without permission. After the changes have been made and saved. Remember to restore the file and the permissions of the ETC directory.

The four kinds of Lion system changes in the Hosts of the method will not appear without the permission to change the file prompts. This hint is actually a higher performance of Lion security, the above several methods in the 10.6 system can be used, at least a few of the lion system is the most simple way to change the Hosts file. In addition, you can see that the above three methods are required to operate in the terminal, and for just using the MAC. And users who have not played Linux can be considered a hassle. In fact the terminal is very easy, it is a few commands. And it's very powerful, and it's capable of very many unexpected features. Therefore, for the classmate just with the MAC must not be the terminal such command line operation is intimidated. Basically you just need to copy the command, and then paste it in to press ENTER to be able to, what is the difficulty of it?

Teach your Mac OS system four ways to change the Hosts file

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.