Posts Tagged: DNS


15
十一 11

getaddrinfo()与DNS轮询

同事发现一个怪现象,在使用libcurl访问一个做了DNS轮询的域名,发现“十分”地不均衡,并且就像libcurl有智能一样,总是选择跟自己在同一机房的IP访问。

经过分析发现:libcurl和 wget都使用了glibc提供的 getaddrinfo()来解析域名的IP地址。RHEL5(应该其它版本也如此)系统上glibc 实现的getaddrinfo函数,遵循了RFC3484第三章第九条规则对于解析地址排序的 规定,即解析出来的IP地址依照与发起请求的源地址的最长匹配前缀排序。简单的说,与发起请求的机器在同一个子网的IP会被优先选取。

要解决这个问题,可以通过/etc/gai.conf来改变getaddrinfo函数的行为。

man gai.conf查询详细信息。

这里有一程序,可以测试getaddrinfo()与gethostbyname()时解析的命中情况,可用于测试、观察这个现象。

http://daniel.haxx.se/roundrobin.c


9
十二 08

域名解析慢的问题

avahi-daemon – The Avahi mDNS/DNS-SD daemon

The  Avahi  mDNS/DNS-SD daemon implementing Apple’s ZeroConf architecture (also known as “Rendezvous” or “Bonjour”). The daemon registers local IP addresses and static services using mDNS/DNS-SD and provides two IPC APIs for local programs to make  use  of  the  mDNS  record cache  the  avahi-daemon  maintains. First there is the so called “simple protocol” which is used exclusively by avahi-dnsconfd (a daemon which configures unicast DNS servers using server info published via mDNS) and nss-mdns (a libc NSS plugin, providing name resolution via mDNS). Finally there is the D-Bus interface which provides a rich object oriented interface to D-Bus enabled applications.

一同事的本本连接服务器很慢,感觉像是在做反向解析。服务器上的SSH Daemon我已经配置了UseDNS no,所以应该不是服务器端的问题。后来发现ping一个域名也很慢,加上-n参数就很快。

我们刚搬机房的时候,服务器上也发生过类似的事情。不过当时是从任何地方ping机房的服务器都会很慢。

strace了一下ping www.bsdmap.com

发现要调用avahi-daemon:
connect(4, {sa_family=AF_FILE, path=”/var/run/avahi-daemon/socket”}, 110) = 0

于是,停掉avahi-daemon服务。一切恢复正常!看来是avahi-daemon出了问题。

avahi-daemon是一个苹果电脑上的“零配置(跟网络有关)”构架的实现。个人理解像是桌面系统上东西,服务器上应该用不着。


29
八 08

DNS的SOA记录

笔记:关于DNS的SOA记录的各项含义。

以我的域名为例:

bsdmap.org    IN    SOA    ns2.xinnetdns.com.    hostmaster.xinnetdns.com. (
1083128244    ; serial number
3600                ; refresh
1800                ; retry
604800            ; expire
7200  )             ; min TTL

SOA值
序列号:格式为yyyymmddnn,nn代表这一天是第几次修改。在每次更新了你的区数据后不要忘了增加序列号的值。辅名字服务器通过比较这个序列号是否加载一份新的区数据拷贝。
refresh(刷新):告诉该区的辅名字服务器相隔多久检查该区的数据是否是最新的。
retry(重试):如果辅名字服务器超过刷新间隔时间后无法访问主服务器,那么它就开始隔一段时间重试连接一次。这个时间通常比刷新时间短,但也不一定非要这样。
expire(过期或期满):如果在期满时间内辅名字服务器还不能和主服务器连接上,辅名字服务器就使用这个我失效。这就意味着辅名字服务器将停止关于该区的回答,因为这些区数据太旧了,没有用了。设置时间要比刷新和重试时间长很多,以周为单位是较合理的。
否定缓存TTL(生存期):这个值对来自这个区的权威名字服务器的否定响应都适用。
新版的bind的时间设置灵活了很多,以前只接收以秒为单位(一周有608400秒)。现在可以用h(小时),d(天),w(周)表示。
RFC1537建议顶级名字服务器采用以下值:
refresh        24h
retry              2h
expire         30d
否定缓存ttl     4d

参考:http://www.ripe.net/docs/ripe-203.html


29
七 08

免费、详尽的DNS检查工具/网站

http://www.checkdns.net


27
七 08

缓存DNS查询,解决DNS查询慢的问题

pdnsd, written by Thomas Moestl, is a proxy DNS server with permanent caching (the cache contents are written to hard disk on exit) that is designed to cope with unreachable or down DNS servers (for example in dial-in networking).
The official pdnsd homepage by the original author can be found at http://home.t-online.de/home/Moestl/, but unfortunately pdnsd is no longer being maintained by him. As far as I know I am presently the only one actively working on the code, so if you want the latest features and fixes, this is the place to get them.

主页:http://www.phys.uu.nl/~rombouts/pdnsd.html

配置起来非常简单:

1. 将example配置文件复制一份

2. 将:

server {
label= “myisp”;
ip = 58.215.76.163

IP换成自己的ISP提供的DNS地址,多个用”,”隔开

3. 最重要的一步,许多DNS不接受”ping”测试,所以要将:

uptest=if/ping 改成

uptest=query

4.  将/etc/resolv.con里的nemeserver改成127.0.0.1

PS:

pdnsd.conf是可以控制pdnsd的返回结果的,就是说,可以通过配置pdnsd来达到自定义解析结果的日的。

另外,我们使用pdnsd的根本原因是因为ISP的DNS不稳定,解析慢。pdnsd可以直接从根服务器查询开始,更不必依赖于ISP的DNS。但是需要说明的是,使用了CDN服务的站点,可以会取到不精确的地址,而导致访问速度不佳。