简体   繁体   English

如何从网站的DNS获取负载均衡器的URL或IP?

[英]How to get the URL or IP of a load balancer from DNS of a website?

nslookup is a network administration command-line tool available for many computer operating systems for querying the Domain Name System (DNS) to obtain domain name or IP address mapping or for any other specific DNS record. nslookup是一种网络管理命令行工具,可用于许多计算机操作系统,用于查询域名系统(DNS)以获取域名或IP地址映射或任何其他特定DNS记录。

So, nslookup returns the endpoint(s) of a url. 因此,nslookup返回url的端点。 But if I needs to get the intermediate url/ip, how do I do so? 但是,如果我需要获得中间url / ip,我该怎么办?

For eg. 例如。 If www.example.com is hosted on 2 instances on AWS behind an ELB(Elastic load balancer), then 如果www.example.com托管在ELB(弹性负载均衡器)后面的AWS上的2个实例上,那么

nslookup www.example.com

will return the IPs of the 2 instances. 将返回2个实例的IP。 Is there any way to get the dns/ip of the load balancer? 有没有办法获得负载均衡器的dns / ip?

I use the following function in C to resolve a URL to endpoints. 我在C中使用以下函数来解析到端点的URL。

int getaddrinfo(const char *node, const char *service,
                const struct addrinfo *hints,
                struct addrinfo **res);

Is there a way to get the load balancer's URL/IP in C? 有没有办法在C中获取负载均衡器的URL / IP?

I think you are getting confused by the IP addresses returned by nslookup. 我认为你对nslookup返回的IP地址感到困惑。 Those IP addresses are the actual addresses of your ELB, not the balanced instances. 这些IP地址是ELB的实际地址,而不是平衡实例。

The reason why a load balancer offers multiple addresses is basically to provide a fallback, cover different availability zones (if you would have 3 instances in 3 different availability zones, you would see 3 IPs) etc. However please bear in mind that those IP addresses are not fixed and might change any time, therefore use the provided DNS for the balancer instead whenever applicable. 负载均衡器提供多个地址的原因基本上是提供后备,覆盖不同的可用区域(如果您在3个不同的可用区域中有3个实例,则会看到3个IP)等。但请记住这些IP地址不固定并且可能随时更改,因此在适用时使用提供的DNS作为平衡器。

Apart from that you are on the right track using getaddrinfo . 除此之外,你使用getaddrinfo在正确的轨道上。

nslookup and in C getaddrinfo will return the IP (IPv4 -A record- or IPv6 -AAAA record-) address that was configured in DNS. nslookup和C getaddrinfo将返回在DNS中配置的IP(IPv4 -A记录或IPv6 -AAAA记录)地址。 If the address configured is the IP address of an instance or two IP addresses of two instances it will return that. 如果配置的地址是一个实例的IP地址或两个实例的两个IP地址,它将返回该地址。 If the configured IP address was the Elastic IP assigned to ELB, nslookup (and getaddrinfo) will return the EIP of the ELB. 如果配置的IP地址是分配给ELB的弹性IP,则nslookup(和getaddrinfo)将返回ELB的EIP。 You can configure that in DNS system for the authoritative name servers to return the corresponding IP address or you can also write the mapping in the hosts file. 您可以在DNS系统中为权威名称服务器配置以返回相应的IP地址,也可以在hosts文件中编写映射。

Regarding ELB. 关于ELB。 When you create an ELB it works for any availability zone in the specified region and it will load balance among all the instances attached to it internally. 创建ELB时,它适用于指定区域中的任何可用区域,并且将在内部附加到它的所有实例之间进行负载平衡。 For that you need cross-zone load balancing. 为此,您需要跨区域负载平衡。 Those instances can be in different availability zones wihtin the same region. 这些实例可以位于同一地区的不同可用区域中。

http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/how-elb-works.html#request-routing http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/elb-internet-facing-load-balancers.html http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/how-elb-works.html#request-routing http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/elb-internet -facing的负载balancers.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM