How to Find the IP Address of a Website Using DNS

How to Find the IP Address of a Website Using DNS

How to Find the IP Address of a Website Using DNS

A website opens in a browser, but its address bar shows a name rather than the numerical address used for a connection. You can find a website’s IP addresses with a DNS lookup: choose the exact hostname, request both address types, and read the answers separately. You can get a site’s IP addresses in a few commands on your own computer.

Get the IP Address of a Website with nslookup

The Domain Name System (DNS) translates names into records that computers can use. An A record supplies an IPv4 address; an AAAA record supplies an IPv6 address. A site can have either type, both, or several addresses of one type.

First choose the hostname from the URL. In https://www.example.com/articles, the hostname is www.example.com: omit https:// and /articles. The name example.com is a different hostname and can return different answers. If the browser redirects to another name, look up that destination too.

To find the IP address of a website, open Command Prompt on Windows or a terminal on macOS or Linux. Run these commands, replacing the example name with the hostname you need:

nslookup -type=A www.example.com
nslookup -type=AAAA www.example.com

To get a website’s IPv4 address, use the first request; the second asks for IPv6. Microsoft’s nslookup documentation describes the record-type option. The lines labeled Server and Address near the top identify the DNS resolver that answered your query; look below the name being queried for the site’s returned addresses.

For an illustration, imagine the A answer lists 192.0.2.10 and 192.0.2.11, while the AAAA answer lists 2001:db8::10. These are documentation examples, not addresses to use for a real site. The dotted numbers are IPv4; the colon-separated value is IPv6.

Read the answer, including aliases

What is the IP address of a website when the response lists several? Each returned address is part of that lookup’s answer. A service may distribute requests across multiple endpoints for capacity or availability. The order may vary; the first line alone does not identify a preferred server in every situation. Record the complete list and the time of your test if you plan to compare results. What address does the site use for IPv6? The AAAA answer provides that part of the picture.

A response may also show a canonical name, or CNAME: an alias directing the lookup toward another hostname. The final A or AAAA values are the addresses to examine. If an A lookup succeeds but AAAA has no answer, that name may have no published IPv6 address. A timeout or server failure is different: the resolver did not provide a usable answer, so try again or compare another resolver before drawing a conclusion.

You can find the IP address of the website again after a change and compare both sets of records. It helps to keep the hostname and record type beside each result.

Why another lookup can differ

A content delivery network (CDN) places servers in multiple locations and may return an address for its network rather than the site’s origin server, where the site’s content is hosted. A proxy can also sit between visitors and the origin. For example, Cloudflare explains that proxied records return its network addresses. Finding a site’s IP address through DNS therefore tells you where that lookup directs connections; it does not establish the private origin address.

DNS responses can vary with the resolver, its location, and the time of the query. Resolvers cache answers for a period governed by the record’s time to live, or TTL. After a record changes, one resolver may still have an older cached answer while another has refreshed it. Load balancing can also change the addresses or their order. These differences matter when you get the IP addresses of a website to investigate an intermittent connection: compare the same hostname, record type, resolver, and time.

You can get the IP address of a website from a specific resolver by adding its address after the hostname. For example, nslookup -type=A www.example.com 1.1.1.1 asks that resolver for the A answer. Repeat with -type=AAAA for IPv6. Get the website’s IP address from your default resolver too, allowing for caching and location; a difference alone does not identify a fault.

Use the result in context

If you need to find a website’s current IP address for a connectivity test, save all returned values and note which resolver supplied them. Test IPv4 and IPv6 separately if your diagnostic tool supports both. An address responding to a network probe does not by itself confirm that the website’s HTTPS service is working: the service may share an address with other sites and expects the hostname during the connection.

The website’s DNS answer is also distinct from your public IP address, which identifies your network’s outward-facing connection. If the question is which IP address a website uses, query its hostname. If you need the address your own connection presents to other services, use a service designed to show your public IP instead.

Quick reference

  1. Take the hostname from the URL; include www if present.
  2. Run an A lookup and an AAAA lookup with nslookup.
  3. Save every returned address, the resolver, and the time. Distinguish the resolver’s own address from the answer.
  4. Compare another resolver when investigating differences, and account for caching and CDN routing.
  5. Treat the result as the destination returned by DNS for that lookup, rather than a permanent origin address.