Linux /etc/hosts 主机名静态查询表

本文介绍了在系统启动且DNS未工作时,如何通过/etc/hosts文件实现主机名与IP地址之间的映射。该文件对于IPv4和IPv6环境下网络程序的正常运行至关重要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

用途:

关联主机名和IP地址

在机器启动时,在DNS正常工作前,需要知道一些主机名和IP地址的映射关系,这个映射关系就保存在/etc/hosts文件中,在DNS不能正常工作是,系统中所有的网络程序将查看该文件以决定IP地址对应的主机名。

格式:

每行一个IP地址

IP_address canonical_hostname [aliases...]

注释:

从 #开始,到一行的结束。

示例一:

127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6

示例二:

# The following lines are desirable for IPv4 capable hosts
       127.0.0.1       localhost

       # 127.0.1.1 is often used for the FQDN of the machine
       127.0.1.1       thishost.mydomain.org  thishost
       192.168.1.10    foo.mydomain.org       foo
       192.168.1.13    bar.mydomain.org       bar
       146.82.138.7    master.debian.org      master
       209.237.226.90  www.opensource.org

       # The following lines are desirable for IPv6 capable hosts
       ::1             localhost ip6-localhost ip6-loopback
       ff02::1         ip6-allnodes
       ff02::2         ip6-allrouters

 

转载于:https://www.cnblogs.com/rushoutasia/p/5643310.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值