dns配置文件 /etc/resolv.conf中search设置详解

简介

search swg.local consul.local
nameserver 103.224.222.222

dns配置文件 /etc/resolv.conf 中常看到有search 设置,以前以为是根据search 中的域去指定nameserver,其实不是这样用的。它的一个用处是程序只需要知道主机名就可以解析到ip,不必知道域后缀是什么。下面介绍下设置了search后的解析规则。

FQDN(Fully Qualified Domain Name)含义是完整的域名. 例如, 一台机器主机名(hostname)是www, 域后缀(domain)是baidu.com, 那么该主机的FQDN应该是www.baidu.com. 最后是以"."来结尾的, 但是大部分的应用和服务器都允许忽略最后这个点. 所有大家直接输入 www.baidu.com 也可以识别

解析 shell-server

解析串中无.,先认为是主机名,添加域后缀后查询,查不到再认为其实域名去查询


#host -a shell-server

Trying "shell-server.swg.local"
Trying "shell-server.consul.local"
Trying "shell-server"
Host shell-server not found: 3(NXDOMAIN)
Received 105 bytes from 103.224.222.222#53 in 10 ms

解析 shell-server.nginx

解析串中有.,先以域名查询,查询不到认为是主机名,添加域后缀后查询

# host -a shell-server.nginx
Trying "shell-server.nginx"
Received 111 bytes from 103.224.222.222#53 in 18 ms
Trying "shell-server.nginx.swg.local"
Trying "shell-server.nginx.consul.local"
Host shell-server.nginx.consul.local not found: 5(REFUSED)
Received 49 bytes from 103.224.222.223#53 in 9 ms

解析 shell-server.

解析串以.结尾,认为是完毕域名不自动添加域后缀

# host -a shell-server.

Trying "shell-server"
Received 105 bytes from 103.224.222.222#53 in 2 ms
Trying "shell-server"
Trying "shell-server"
Host shell-server. not found: 3(NXDOMAIN)
Received 105 bytes from 103.224.222.222#53 in 2 ms

参考

https://access.redhat.com/documentation/zh-cn/red_hat_enterprise_linux/7/html/networking_guide/sec-using_the_networkmanager_command_line_tool_nmcli
http://dns-learning.twnic.net.tw/bind/intro4.html
https://unix.stackexchange.com/questions/128091/no-domain-defined-in-etc-resolv-conf
https://www.cyberciti.biz/faq/change-dns-ip-address-rhel-redhat-linux/

你可能感兴趣的:(Linux,网络)