简体   繁体   中英

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.

So, nslookup returns the endpoint(s) of a url. But if I needs to get the intermediate url/ip, how do I do so?

For eg. If www.example.com is hosted on 2 instances on AWS behind an ELB(Elastic load balancer), then

nslookup www.example.com

will return the IPs of the 2 instances. Is there any way to get the dns/ip of the load balancer?

I use the following function in C to resolve a URL to endpoints.

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?

I think you are getting confused by the IP addresses returned by nslookup. Those IP addresses are the actual addresses of your ELB, not the balanced instances.

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.

Apart from that you are on the right track using getaddrinfo .

nslookup and in C getaddrinfo will return the IP (IPv4 -A record- or IPv6 -AAAA record-) address that was configured in DNS. If the address configured is the IP address of an instance or two IP addresses of two instances it will return that. If the configured IP address was the Elastic IP assigned to ELB, nslookup (and getaddrinfo) will return the EIP of the ELB. 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.

Regarding 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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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