背景html
公司新部署几台服务器,安装最新的CentOS 6.5操做系统,但当执行ping或dig操做时,等待时间较长,不能忍受,而同网络下的CentOS 5.6系统却正常linux
同时在远程登陆(SSH)时,也出现卡顿的现象,登陆不太流畅
安全
原理bash
DNS解析缓慢的缘由是CentOS 6/REHL 6 老是须要等待AAAA(IPv6)的结果,即便IPv6已在网络设置中禁用服务器
出现SSH登陆缓慢的问题,多是“GSSAPIAuthentication认证与UseDNS反向解析”耗费时间致使的网络
解决方案
ssh
取消GSSAPIAuthentication认证与UseDNS反向解析功能:socket
1
2
3
4
5
|
vi
/etc/ssh/sshd_config
GSSAPIAuthentication no
#通用安全服务应用程序接口(GSSAPI) 是为了让程序可以访问安全服务的一个应用程序接口,取消这个认证。
UseDNS no
#DNS反向解析,设置为no
|
在resolv.conf中添加single-request-reopen选项ide
1
2
3
4
|
cat
/etc/resolv
.conf
# Generated by NetworkManager
options single-request-reopen
nameserver 192.168.18.77
|
这实际上是CentOS 6的一个Bug,可查询到的解释以下:ui
1
2
|
The logic behind so long
time
for
DNS resolution lies
in
fact that resolver use same socket
for
A(ipv4) and AAAA(IPv6) DNS record resolution. Some hardware mistaking send one reply and left resolver
in
waiting mode. Enabling option single-request-reopen will instruct resolver to use new socket
if
for
AAAA
if
require.
缘由是:CentOS 6中的DNS解析器对于ipv4和ipv6都使用同一个socket接口,在同时发出ipv4和ipv6解析请求后,只会收到一个ipv4的解析响应,此时socket将一处于“等待”模式,等待ipv6的解析响应,故致使解析缓慢;添加single-request-reopen后就能够从新打开一个新的socket接收ipv6的解析响应,而不影响ipv4的解析响应。
|
防止修改resolv.conf文件后,重启网络,会致使文件被重置的状况,缘由是启用了NetworkManager 服务
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
1.建立一个脚本。
vi
/etc/NetworkManager/dispatcher
.d
/15-resolv
#!/bin/bash
# Description : script to override default resolv.conf file
# with customized file.
cp
-f
/etc/resolv
.conf.custom
/etc/resolv
.conf
2.设置文件权限
chmod
u+x
/etc/NetworkManager/dispatcher
.d
/15-resolv
3.建立一个文件
vi
/etc/resolv
.conf.custom
options single-request-reopen
nameserver xx.xx.xx.xx
4.重启服务
service NetworkManager restart
|
转载地址:http://xxrenzhe.blog.51cto.com/4036116/1340103
4. 参考资料
DNS解析缓慢问题:
https://wiki.echocat.org/display/ECHOCAT/2012/04/20/CentOS+6+and+slow+DNS
http://linuxmantra.com/2013/07/single-request-reopen-option-in-resolv-conf.html
single-request-reopen的详细解释:
http://www.man7.org/linux/man-pages/man5/resolver.5.html
防止resolv.conf文件被复写的状况:
http://www.linuxidc.com/Linux/2013-06/85636.htm