/etc/resolv.conf文件中的search项作用

resolv.conf文件中有search项时,主机名解析规则顺序: 
DNS配置文件如下:

# vi /etc/resolv.conf
# Generated by NetworkManager
search openstack.local dev.com example.local
nameserver 192.168.122.21
  • 1
  • 2
  • 3
  • 4

例1:查询主机名,因为主机名后面没有点,就认为是主机名,所以先添加search里的每一项依次组成FQDN(完全合格域名)来查询,完全合格域名查询未找到,就再认为主机名是完全合格域名来查询。

# host -a centos7-bind-1
Trying "centos7-bind-1.openstack.local"
Trying "centos7-bind-1.dev.com"
Trying "centos7-bind-1.example.local"
Trying "centos7-bind-1"
;; connection timed out; no servers could be reached
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

例2:查询主机名,因为主机名中有点(不是末尾有点),就认为是完全合格域名,先用它来查询,查询失败就把它当成是主机名来进行,添加search里的每一项组成FQDN(完全合格域名)来查询。

# host -a centos7-bind-1.com
Trying "centos7-bind-1.com"
Received 109 bytes from 192.168.122.21#53 in 177 ms
Trying "centos7-bind-1.com.openstack.local"
Trying "centos7-bind-1.com.dev.com"
Trying "centos7-bind-1.com.example.local"
Host centos7-bind-1.com not found: 3(NXDOMAIN)
Received 125 bytes from 192.168.122.21#53 in 55 ms
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

例3:查询主机名,因为主机名中末尾有点,则认为是完全合格域名,只用它来查询(不会再添加search里的每一项)。查询次数会与search里项域名个数有关。

# host -a centos7-bind-1.
Trying "centos7-bind-1"
;; connection timed out; trying next origin
Trying "centos7-bind-1"
;; connection timed out; trying next origin
Trying "centos7-bind-1"
;; connection timed out; trying next origin
Trying "centos7-bind-1"
;; connection timed out; no servers could be reached
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

DNS查询工具:host命令介绍 
用法:host [-a] FQDN [server] 
host -l domain [server] 
-a参数:显示查询的所有详细信息。 
-l参数:如果后面的domain允许allow-transfer时,则列出该domain所管理的所有主机数据。 
server参数:这个参数可有可无,当想要利用非 /etc/resolv.conf 内的DNS主机,来查询主机名与 IP 的对应时,就可以利用这个参数了。

host命令使用例(列出该domain所管理的所有主机数据):

# host -l example.local  192.168.122.84
Using domain server:
Name: 192.168.122.84
Address: 192.168.122.84#53
Aliases: 

example.local name server ns.example.local.
dns.example.local has address 192.168.123.10
ns.example.local has address 192.168.122.84
ns.example.local has IPv6 address ::1
sss.example.local has address 192.168.123.9
www.example.local has address 192.168.123.8
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值