当前位置: 技术问答>linux和unix
一个gethostbyname的疑问
来源: 互联网 发布时间:2016-04-20
本文导语: struct hostent *gethostbyname(const char *name); 我用www.sina.com试了一下,每次运行后返回的hostent结构里的IP地址的序列,不仅仅只是顺序不一样,而且内容都可能不一样,有人知道为什么吗?请指教! 附测试数据: [root@loc...
struct hostent *gethostbyname(const char *name);
我用www.sina.com试了一下,每次运行后返回的hostent结构里的IP地址的序列,不仅仅只是顺序不一样,而且内容都可能不一样,有人知道为什么吗?请指教!
附测试数据:
[root@localhost addrtoname]# ./addr www.sina.com
Official hostname: ara.sina.com.cn
alias: www.sina.com
alias: us.sina.com.cn
alias: news.sina.com.cn
alias: jupiter.sina.com.cn
address: 58.63.236.49
address: 58.63.236.50
address: 58.63.236.26
address: 58.63.236.27
address: 58.63.236.28
address: 58.63.236.37
address: 58.63.236.38
address: 58.63.236.39
address: 58.63.236.40
address: 58.63.236.41
address: 58.63.236.42
address: 58.63.236.43
address: 58.63.236.44
address: 58.63.236.45
address: 58.63.236.46
address: 58.63.236.47
[root@localhost addrtoname]# ./addr www.sina.com
Official hostname: ara.sina.com.cn
alias: www.sina.com
alias: us.sina.com.cn
alias: news.sina.com.cn
alias: jupiter.sina.com.cn
address: 58.63.236.31
address: 58.63.236.32
address: 58.63.236.33
address: 58.63.236.34
address: 58.63.236.35
address: 58.63.236.36
address: 58.63.236.37
address: 58.63.236.38
address: 58.63.236.39
address: 58.63.236.40
address: 58.63.236.41
address: 58.63.236.42
address: 58.63.236.43
address: 58.63.236.44
address: 58.63.236.45
address: 58.63.236.46
我用www.sina.com试了一下,每次运行后返回的hostent结构里的IP地址的序列,不仅仅只是顺序不一样,而且内容都可能不一样,有人知道为什么吗?请指教!
附测试数据:
[root@localhost addrtoname]# ./addr www.sina.com
Official hostname: ara.sina.com.cn
alias: www.sina.com
alias: us.sina.com.cn
alias: news.sina.com.cn
alias: jupiter.sina.com.cn
address: 58.63.236.49
address: 58.63.236.50
address: 58.63.236.26
address: 58.63.236.27
address: 58.63.236.28
address: 58.63.236.37
address: 58.63.236.38
address: 58.63.236.39
address: 58.63.236.40
address: 58.63.236.41
address: 58.63.236.42
address: 58.63.236.43
address: 58.63.236.44
address: 58.63.236.45
address: 58.63.236.46
address: 58.63.236.47
[root@localhost addrtoname]# ./addr www.sina.com
Official hostname: ara.sina.com.cn
alias: www.sina.com
alias: us.sina.com.cn
alias: news.sina.com.cn
alias: jupiter.sina.com.cn
address: 58.63.236.31
address: 58.63.236.32
address: 58.63.236.33
address: 58.63.236.34
address: 58.63.236.35
address: 58.63.236.36
address: 58.63.236.37
address: 58.63.236.38
address: 58.63.236.39
address: 58.63.236.40
address: 58.63.236.41
address: 58.63.236.42
address: 58.63.236.43
address: 58.63.236.44
address: 58.63.236.45
address: 58.63.236.46
|
猜想:
1. 大型的服务(比如web server)为了负载平衡和容灾难,通常不可能只有一台服务器,而是有多台服务器同时运行在网络上!在DNS配置中,通过配置一个域名对应多个IP来实现了简单的客户访问负载均衡。也就是可以看到上面的有个多个IP的原因吧
2. 为什么每次结果不一样呢? 估计是他们DNS Server里面的配置策略导致的(一种随机的,动态的刷新域名与IP绑定的策略吧),这个没有深入研究过,估计要研究DNS server方面的东东才能完全搞明白。
good luck!
1. 大型的服务(比如web server)为了负载平衡和容灾难,通常不可能只有一台服务器,而是有多台服务器同时运行在网络上!在DNS配置中,通过配置一个域名对应多个IP来实现了简单的客户访问负载均衡。也就是可以看到上面的有个多个IP的原因吧
2. 为什么每次结果不一样呢? 估计是他们DNS Server里面的配置策略导致的(一种随机的,动态的刷新域名与IP绑定的策略吧),这个没有深入研究过,估计要研究DNS server方面的东东才能完全搞明白。
good luck!
|
呵呵,就是楼上说的那样
我们公司也是这样做的
你每次去ping它都得到不同的ip
这样就把请求分散到很多机器去了
我们公司也是这样做的
你每次去ping它都得到不同的ip
这样就把请求分散到很多机器去了