浏览 3076 次
锁定老帖子 主题:Erlang DNS解析顺序问题
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2010-02-04
最后修改:2010-02-04
Erlang 的 DNS 解析方法有包括 file(读取 /etc/hosts 文件)、dns(Erlang 自己的 DNS 客户端)、native(调用外部程序 inet_gethost 用 libc 的 gethostbyname 函数解析域名) 在内的好几种方式,可以在 kernel inetrc 文件中以 {lookup, [...]} 形式指定多种 DNS 解析方法的应用顺序。在 inet:gethostbyname_tm/4 函数中可以发现任意一个域名的解析顺序是:
由于 dns 方式比 native 方式效率高、并发能力好,所以配置 lookup 为 [file, dns] 是比较常见的。这一解析顺序通常情况下工作的都很好,但若 DNS 服务器会将所有无法正常解析的域名解析为一个统一的 IP 地址(例如大部分公司网络环境),而你尝试去解析一个已经是 IPv4/v6 地址的字符串,就会产生严重的问题。Why?因为在第 1 步中,dns 方法会将已经是 IP 地址的字符串当作域名发送给 DNS 服务器,由于前述的 DNS 服务器特性,解析结果就会变成另外一个驴头不对马嘴的 IP 地址,造成严重的混乱。
这一问题影响面很广,基础库中的 gen_tcp、gen_udp、http 等都会受波及。目前的临时解决方法有这么几种:
该问题我已经发到了 erlang-bugs@erlang.org 并得到了 Raimo Niskanen 的积极回应,有望在下个版本中得到改进。
Raimo Niskanen 写道
This leaves us some other alternatives:
1) To extend the 'file' or the 'dns' lookup methods with IP string detection. 2) To do only do IP string detection when the 'native' lookup method is not used, but to do it first instead of last as today, within the inet:gethostbyname lookup method wrapper itself. 3) To introduce a new lookup method e.g 'ipstring' that the user can insert in the lookup chain wherever suitable. I do not like 1) since it would make either of those lookup methods impure, harder to test and harder to explain. I prefer 2) because it would behave kind of natural. However, 3) is the purest but would require manual configuration in more cases. But 2) wins... At least until someone convinces me otherwise. 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2010-02-25
DNS解释几乎所有的平台都做的很复杂, Erlang的是非常复杂...
|
|
返回顶楼 | |