Linux /etc/resolv.conf 配置DNS

来源:互联网 发布:零编程基础学plc 编辑:程序博客网 时间:2024/05/19 04:07

文件/etc/resolv.conf配置DNS客户,它包含了主机的域名搜索顺序和DNS服务器的地址,每一行应包含一个关键字和一个或多个的由空格隔开的参数。下面是一个例子文件: 

  search mydom.edu.cn
  nameserver 210.34.0.14
  nameserver 210.34.0.2

  合法的参数及其意义如下:


  nameserver 表明DNS服务器的IP地址。可以有很多行的nameserver,每一个带一个IP地址。在查询时就按nameserver在本文件中的顺序进行,且只有当第一个nameserver没有反应时才查询下面的nameserver。 

  domain   声明主机的域名。很多程序用到它,如邮件系统;当为没有域名的主机进行DNS查询时,也要用到。如果没有域名,主机名将被使用,删除所有在第一个点( .)前面的内容。 

  search   它的多个参数指明域名查询顺序。当要查询没有域名的主机,主机将在由search声明的域中分别查找。domain和search不能共存;如果同时存在,后面出现的将会被使用。 

  sortlist  允许将得到域名结果进行特定的排序。它的参数为网络/掩码对,允许任意的排列顺序。 

  Red Hat中没有提供缺省的/etc/resolv.conf文件,它的内容是根据在安装时给出的选项动态创建的。

原文链接:
 Linux下/etc/resolv.conf 配置DNS客户

在/etc/resolv.conf 配置文件:domain 和search作用是一样的

下面的说明更清晰

domain linpro.no
search linpro.no uio.no ifi.uio.no

domain function:

Had I typed telnet math.uio.no. with the trailing dot, the resolver would have known it was an FQDN and would have looked up math.uio.no at once, without trying to append the specified domain first. Not all applications are tolerant of the trailing dot, though, so it can't always be specified.

search function:

When ssh gram is executed, the resolver first looks for gram.linpro.no, which does not exist; then gram.uio.no, which does not exist, either; and finally gram.ifi.uio.no, which will succeed because it does exist

原文链接:/etc/resolv.conf中关键字search和domain的作用

关于domain和search与/etc/hosts的区别在《鸟哥的linux私房菜(网络架设)》第十九章 DNS服务器 小节:Client 端的设定 中有说:
· /etc/hosts :刚刚上面就提过了,这个是最早的 hostname 对应 IP 的档案; 

· /etc/resolv.conf :这个就是设定你 Client 端连上 DNS 主机的 IP 设定文件; 

· /etc/nsswitch.conf:这个档案则是在『决定』先要使用 /etc/hosts 还是 /etc/resolv.conf的设定!

  一般而言, Linux 的预设 hostname 搜寻都是先 /etc/hosts 来的,为什么呢?你可以查看一下
/etc/nsswitch.conf ,并找到 hosts 的项目: 

[root@linux ~]# vi /etc/nsswitch.conf hosts: files dns
  上面那个 files 就是使用 /etc/hosts 而最后的 dns 则是使用 /etc/resolv.conf 的 DNS 主机 IP搜 
寻啦!因此,你可以先以 /etc/hosts 来设定 IP 对应ㄋㄟ!当然啦,你也可以将他调换过来,不过,总是
/etc/hosts 比较简单,所以将他摆在前面比较好啦!

  好啦,既然我们是要进行 DNS 测试的,那么 /etc/resolv.conf 的内容,自然就要填写我们自己的IP
啰!所以你应该这样写: 

[root@linux ~]# vi /etc/resolv.conf nameserver 192.168.1.254 nameserver 168.95.1.1 nameserver 139.175.10.20
  nameserver 可以设定多个,但是由于 nameserver 是一个一个的追查下来的,所以,你的 DNS 主机的 IP 要写在最上面喔!然后就可以开始测试了!

0 0
原创粉丝点击