如何编辑主机文件 – 窗口 | 苹果系统 | 的Linux

什么是主机文件?

A host file is a local plain text file that maps server or host names to IP addresses. This file has been in use since the days of ARPANET. It was the original method of converting host names to specific IP addresses. A host file is usually the first process in the domain name resolution procedure. Here is an example of a hosts file entry.

 

127.0.0.1 localhosts #loopback

Where is a Host File Located On your computer?

The location of a host file will differ by operating system. The typical locations are noted below.

  • 视窗 10 – “C:\Windows\System32\drivers\etc\hosts”
  • 的Linux – “/etc/hosts”
  • Mac OS X – “/private/etc/hosts”

Editing a Host File

Editing your host file causes your local machine to look directly at the Internet Protocol (知识产权) address that you specify.

Editing the host file involves adding two entries to it. Each entry contains the IP address to which you want the site to resolve and a version of the Internet address.

Let’s Edit Host File On Windows

视窗 10 和窗户 8

Use the following instructions if you’re running Windows 10 或窗户 8:

  1. – 按下 视窗 钥匙.
  2. – 类型 Notepad in the search field.
  3. In the search results, 右键点击 Notepad 并选择 Run as administrator.
  4. From Notepad, open the following file:C:\Windows\System32\Drivers\etc\hosts
  5. Make the necessary changes to the file.
  6. – 选择 文件 > 保存 to save your changes.

视窗 7 and Windows Vista

Use the following instructions if you’re running Windows 7 or Windows Vista:

  1. – 选择 开始 > All Programs > Accessories.
  2. Right-click Notepad 并选择 Run as administrator.该 Windows needs your permission UAC window appears.
  3. – 点击 Continue to grant permission.Notepad opens.
  4. In Notepad, 选择 文件 > 打开.
  5. – 在里面 File name 场地, enter the following path:C:\Windows\System32\Drivers\etc\hosts
  6. – 选择 打开.
  7. Make the necessary changes to the file.
  8. – 选择 文件 > 保存 to save your changes.

Windows NT, 视窗 2000, and Windows XP

Use the following instructions if you’re running Windows NT, 视窗 2000, or Windows XP:

  1. – 选择 开始 > All Programs > Accessories > Notepad.
  2. – 选择 文件 > 打开.
  3. – 在里面 File name 场地, 输入 C:\Windows\System32\Drivers\etc\hosts.
  4. – 选择 打开.
  5. Make the necessary changes to the file.
  6. – 选择 文件 > 保存 to save your changes.

让我们在 MacOS X 版本上编辑主机文件 10.0 通过 10.12

如果您正在运行 MacOS X,本节提供修改主机文件的说明 10.0 通过 10.12.

macOS X 10.0 通过 10.1.5

如果您运行的是 MacOS X,请使用以下说明 10.0 通过 10.1.5:

  1. – 打开 /应用程序/实用程序/NetInfo 管理器.
  2. – 启用网络信息数据库的编辑 (网络信息), 单击窗口左下角的挂锁图标.
  3. – 输入您的域用户密码并选择 好的.
  4. – 在浏览器视图的第二列, 选择名为 机器.
  5. – 在第三栏中, 选择名为 localhost.
  6. – 来自 编辑 菜单, 选择 重复.出现确认警报.
  7. – 点击 重复.新条目名为 localhost copy 出现,其属性显示在浏览器视图下方.
  8. – 双击 ip_address 属性并输入另一台计算机的IP地址.
  9. – 双击 name 属性并输入要用于另一台计算机的主机名.
  10. – 点击 serves 属性并选择 删除 来自 编辑 菜单.
  11. – 来自 文件 菜单, 选择 保存.出现确认警报.
  12. – 点击 更新此副本.
  13. – 重复步骤 6 通过 12 对于要添加的每个其他主机条目.
  14. – 来自 NetInfo管理器 菜单, 选择 放弃.您不需要重新启动计算机.

macOS X 10.6 通过 10.12

如果您运行的是 MacOS X,请使用以下说明 10.6 通过 10.12:

  1. – 在你的电脑, 选择 应用领域 > 实用工具 > 终奌站 打开终端窗口.
  2. – 在“终端”窗口中输入以下命令以打开 主办 文件:
    sudo nano /private/etc/hosts
    
  3. – 当系统提示您, 输入您的域用户密码.
  4. – 编辑 主办 文件。文件包含注释 (以 # 象征) 和一些默认的主机名映射 (例如, 127.0.0.1 – local host). 在默认映射之后添加新映射.
  5. – 保存主机文件, 按 Ctrl + X.
  6. – 当系统询问您是否要保存更改时, 输入 .
  7. – 强制您的更改生效, 通过输入以下命令刷新 DNS 缓存:
     dscacheutil -flushcache
    
    

让我们在 Linux 上编辑主机文件

如果您运行的是 Linux,请使用以下说明:

  1. – 打开终端窗口.
  2. – 输入以下命令在文本编辑器中打开 hosts 文件:
    sudo nano /etc/hosts
    
  3. – 输入您的域用户密码.
  4. Make the necessary changes to the file.
  5. – 按 控制-X.
  6. – 当系统询问您是否要保存更改时, 输入 .

 

信用

HTTPS://docs.rackspace.com/support/how-to/modify-your-hosts-file/

离开一个答案