什么是/ etc / hosts文件以及如何创建和编辑它?

New comers to the Linux generally asks for what is the purpose and usage of the /etc/hosts file. /etc  directory holds system and service related configuration. hosts file is used to store host name or DNS to IP address resolution. It provides easy way to match a host or DNS name with an IP address.

Linux的新手通常会询问/etc/hosts文件的目的和用途是什么。 /etc目录包含与系统和服务相关的配置。 hosts文件用于存储主机名或DNS到IP地址的解析。 它提供了一种简单的方法来将主机名或DNS名称与IP地址进行匹配。

列出当前主机或DNS到IP地址的分辨率 (List Current Host or DNS to IP Address Resolutions)

We can easily read and print current content of the /etc/hosts file. Its structure is very easy to read as we will examine it below.

我们可以轻松读取和打印/etc/hosts文件的当前内容。 它的结构很容易阅读,我们将在下面进行检查。

$ cat /etc/hosts
List Current Host or DNS to IP Address Resolutions
List Current Host or DNS to IP Address Resolutions
列出当前主机或DNS到IP地址的分辨率

主机名(Hostname)

FQDN is structured naming of hosts in computer networks. You can read following tutorial to get more details about FQDN.

FQDN是计算机网络中主机的结构化命名。 您可以阅读以下教程,以获取有关FQDN的更多详细信息。

What is FQDN (Fully Qualified Domain Name) with Examples?

什么是带有示例的FQDN(完全合格域名)?

We can use FQDN is hosts file but providing host and domain name like below. In this case we add host test which is under lab.com domain with IP address 192.168.1.100

我们可以使用FQDN是hosts文件,但提供如下所示的主机名和域名。 在这种情况下,我们添加在IP地址为192.168.1.100 lab.com域下的主机test

192.168.1.100       test.lab.com

别名 (Alias)

As a system administrator we generally prefer to use practical ways. If the host is in the same domain with us or domain is not important we can just provide the alias like below. In this example we will provide alias test to the IP address 192.168.1.100

作为系统管理员,我们通常更喜欢使用实用的方法。 如果主机与我们位于同一域中,或者域并不重要,我们可以提供如下别名。 在此示例中,我们将为IP地址192.168.1.100提供别名test

192.168.1.100       test

主机名别名 (Alias with Hostname)

hosts file also provides the ability to use both single alias or hostname. We will add them for the same IP address. Syntax is like below.

hosts文件还提供了使用单个alias或主机名的功能。 我们将为相同的IP地址添加它们。 语法如下。

IPADDRESS      HOSTNAME     ALIAS

In this example the IP address is 192.168.1.100 alias is test and hostname is test.lab.com

在此示例中,IP地址为192.168.1.100别名为test ,主机名为test.lab.com

#IPADDRESS      HOSTNAME         ALIAS

192.168.1.100   test.lab.com     test
LEARN MORE  How to Find Detailed Domain Information with whois Command?
了解更多信息如何使用whois命令查找详细的域信息?

翻译自: https://www.poftut.com/what-is-etc-hosts-file-and-how-to-create-and-edit-it/

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值