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

21,270

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.

Share:
21,270
Vineet
Author by

Vineet

Developer by day, Programmer by night.

Updated on November 28, 2020

Comments

  • Vineet
    Vineet over 3 years

    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?