/etc/resolv.conf
注意:如果在 /etc
目录下未找到 resolv.conf
文件,如需使用需要自己手动创建。
/etc/resolv.conf
是DNS客户机的配置文件,用于设置DNS服务器的IP地址及DNS域名,还包含了主机的域名搜索顺序。该文件是由域名解析器(resolver,一个根据主机名解析IP地址的库)使用的配置文件。它的格式比较简单,每行以一个关键字开头,后接一个或多个由空格隔开的参数。
resolv.conf的关键字主要有4个,分别为:
- nameserver:定义DNS服务器的IP地址。可以有很多行的nameserver,每一个带一个IP地址。在查询时就按nameserver在本文件中的顺序进行,且只有当第一个nameserver没有反应时才查询下面的 nameserver。这里最主要的就是nameserver关键字,如果没有指定nameserver就找不到DNS服务,其它关键字是可选的。
- domain:定义本地域名。很多程序用到它,如邮件系统;当为没有域名的主机进行DNS查询时,也要用到。如果没有域名,主机名将被使用,删除所有在第一个点前面的内容。
- search:定义域名的搜索列表。它的多个参数指明域名查询顺序。当要查询没有域名的主机,主机将在由 search 声明的域中分别查找。 domain 和 search 不能共存;如果同时存在,后面出现的将会被使用。
- sortlist:对返回的域名进行排序。允许将得到域名结果进行特定的排序。它的参数为网络/掩码对,允许任意的排列顺序。
[root@sylixos2:/root]# cat /etc/resolv.conf
domain acoinfo.com
search www.acoinfo.com acoinfo.com
nameserver 114.114.114.114
nameserver 8.8.8.8
[root@sylixos2:/root]#
[root@sylixos2:/root]# ifconfig
en1 Link encap: Ethernet HWaddr: f6:4f:aa:4c:69:51
Dev: e1000_0 Ifidx: 2 DHCP: D4 D6 Spd: 1000 Mbps
inet addr: 192.168.196.89 netmask: 255.255.255.0
gateway: 192.168.196.1 broadcast: 192.168.196.255
inet6 addr: fe80::f44f:aaff:fe4c:6951 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
collisions:0 txqueue:0 tcpaf:2 tcpwnd:65535
RX ucast packets:2 nucast packets:1179 dropped:0
TX ucast packets:0 nucast packets:7 dropped:0
RX bytes:78645 (76.8 KB) TX bytes:534 (534.0 B)
lo0 Link encap: Local Loopback
Dev: N/A Ifidx: 1 DHCP: D4 D6 Spd: N/A
inet addr: 127.0.0.1 netmask: 255.0.0.0
P-to-P: 127.0.0.1 broadcast: N/A
inet6 addr: ::1 Scope:Loopback
UP LOOPBACK RUNNING MTU:0 Metric:1
collisions:0 txqueue:0 tcpaf:2 tcpwnd:262140
RX ucast packets:6 nucast packets:0 dropped:0
TX ucast packets:6 nucast packets:0 dropped:0
RX bytes:435 (435.0 B) TX bytes:435 (435.0 B)
dns0: 114.114.114.114
dns1: 8.8.8.8
dns2: 0.0.0.0
dns3: 0.0.0.0
default device is: en1
list net interface: 2
[root@sylixos2:/root]# cat /etc/ho
hosts.equiv hosts
[root@sylixos2:/root]# cat /etc/hosts
127.0.0.1 localhost2 inet
[root@sylixos2:/root]#
[root@sylixos2:/root]#
[root@sylixos2:/root]# ping www.baidu.com
Execute a DNS query...
Pinging www.baidu.com [180.101.50.188]
Pinging 180.101.50.188
Reply from 180.101.50.188: bytes=32 time=18.981ms TTL=48
Reply from 180.101.50.188: bytes=32 time=18.931ms TTL=48
Reply from 180.101.50.188: bytes=32 time=18.839ms TTL=48
Reply from 180.101.50.188: bytes=32 time=19.045ms TTL=48
Ping statistics for 180.101.50.188:
Packets: Send = 4, Received = 4, Lost = 0(0% loss),
Approximate round trip times in milli-seconds:
Minimum = 18.839ms, Maximum = 19.045ms, Average = 18.949ms
[root@sylixos2:/root]# ping www.acoinfo.com
Execute a DNS query...
Pinging www.acoinfo.com [39.106.86.218]
Pinging 39.106.86.218
Reply from 39.106.86.218: bytes=32 time=6.457ms TTL=51
Reply from 39.106.86.218: bytes=32 time=6.007ms TTL=51
Reply from 39.106.86.218: bytes=32 time=5.965ms TTL=51
Reply from 39.106.86.218: bytes=32 time=5.887ms TTL=51
Ping statistics for 39.106.86.218:
Packets: Send = 4, Received = 4, Lost = 0(0% loss),
Approximate round trip times in milli-seconds:
Minimum = 5.887ms, Maximum = 6.457ms, Average = 6.079ms
[root@sylixos2:/root]# ping acoinfo.com
Execute a DNS query...
Pinging acoinfo.com [39.106.86.218]
Pinging 39.106.86.218
Reply from 39.106.86.218: bytes=32 time=6.221ms TTL=51
Reply from 39.106.86.218: bytes=32 time=6.107ms TTL=51
Reply from 39.106.86.218: bytes=32 time=6.213ms TTL=51
Reply from 39.106.86.218: bytes=32 time=6.015ms TTL=51
Ping statistics for 39.106.86.218:
Packets: Send = 4, Received = 4, Lost = 0(0% loss),
Approximate round trip times in milli-seconds:
Minimum = 6.015ms, Maximum = 6.221ms, Average = 6.139ms
[root@sylixos2:/root]#