对于不少电脑新手而言,hosts 这个概念可能相当陌生,甚至连 hosts 文件在电脑中的位置都不清楚。要是使用的是 Mac 电脑,又该如何修改 hosts 文件呢?别担心,在此小编为大家精心准备了一份 macOS 系统下修改 Hosts 文件的详细教程,让我们一起来瞧瞧吧。

一、hosts 究竟是什么

hosts 文件就好比是个人专属的 DNS(域名系统)。当你在浏览器中输入某个网址试图访问时,电脑首先会依据 hosts 文件进行解析。hosts 文件功能十分强大,它不仅能够指定网页对应的 IP 地址,还可以实现屏蔽特定网站的访问,甚至连烦人的广告也能轻松屏蔽掉。

二、macOS 修改 Hosts 文件教程

  1. 打开指定路径:在 Mac 电脑桌面,点击屏幕顶部菜单栏中的 “前往” 选项,接着在弹出的下拉菜单(最下方一排)中点击 “前往文件夹”。
  2. 进入特定目录:在弹出的 “前往文件夹” 窗口中,输入 “/etc”,然后点击 “前往”。
  3. 获取 hosts 文件:在打开的 “etc” 文件夹中,找到 “hosts” 文件,将其直接拖拽到桌面上,参考图示如下:

  1. 选择编辑方式:在桌面上找到刚才拖出的 “hosts” 文件,右键点击该文件,在弹出的菜单中,将鼠标指针滑动到 “打开方式” 选项,然后点击 “文本编辑”。
  2. 编辑 hosts 文件:此时,文本编辑软件会打开 hosts 文件,你可以对其内容进行编辑修改。在文件内容前面加上 “#” 号,这部分内容就会变成注释。例如,下图红框中的内容就是自定义的 hosts 内容。完成修改后,同时按下键盘上的 “command + s” 组合键进行保存,编辑界面如下:

  1. 恢复文件位置:将编辑保存好的 hosts 文件从桌面再次拖拽回 “/etc” 文件夹中。此时系统会弹出认证窗口,点击 “认证” 按钮,接着点击 “替换”,最后输入电脑开机密码即可完成操作。

For many novice computer users, the concept of hosts may be quite unfamiliar, and they may not even know the location of the hosts file in their computers. If you are using a Mac, how can you modify the hosts file? Don’t worry. Here, I have prepared a detailed tutorial on how to modify the Hosts file in the macOS system. Let’s take a look.

I. What Exactly is Hosts

The hosts file is like a personal DNS (Domain Name System). When you enter a website address in your browser to access it, the computer first performs resolution according to the hosts file. The hosts file has very powerful functions. It can not only specify the IP address corresponding to a web page but also block access to specific websites and even easily block annoying ads.

II. Tutorial on Modifying the Hosts File in macOS

  1. Open the Specified Path: On the Mac desktop, click the “Go” option in the top – menu bar. Then, in the drop – down menu that appears, click “Go to Folder”. The operation interface is as follows: [If there is a corresponding picture here, you can add a picture description of “the interface of clicking Go to Folder”]
  2. Enter the Specific Directory: In the “Go to Folder” window that pops up, enter “/etc” and then click “Go”. The specific operation interface is as follows: [If there is a corresponding picture here, you can add a picture description of “the interface of entering /etc”]
  3. Obtain the Hosts File: In the opened “/etc” folder, find the “hosts” file and drag it directly to the desktop. The reference interface is as follows: [If there is a corresponding picture here, you can add a picture description of “dragging the hosts file to the desktop”]
  4. Select the Editing Method: Locate the “hosts” file that was dragged out on the desktop. Right – click on this file. In the pop – up menu, slide the mouse pointer to the “Open With” option and then click “TextEdit”. The interface is shown as follows: [If there is a corresponding picture here, you can add a picture description of “selecting TextEdit to open the hosts file”]
  5. Edit the Hosts File: At this time, the TextEdit software will open the hosts file, and you can edit its content. Adding a “#” sign in front of the content in the file will turn this part of the content into a comment. For example, the content in the red box in the following picture is the custom hosts content. After completing the modification, press the “command + s” combination keys on the keyboard simultaneously to save. The editing interface is as follows: [If there is a corresponding picture here, you can add a picture description of “editing and saving the hosts file”]
  6. Restore the File Location: Drag the edited and saved hosts file from the desktop back to the “/etc” folder. At this point, the system will pop up an authentication window. Click the “Authenticate” button, then click “Replace”, and finally enter the computer’s startup password to complete the operation. [If there is a corresponding picture here, you can add a picture description of “the interface of authenticating and replacing the hosts file”]
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。 (adsbygoogle = window.adsbygoogle || []).push({});