TL;DR / Summary: A single curl or dig command can print your public address, which is useful when a browser is not available or you want an exact string. The answer depends on which host you ask, whether proxy variables are set, and which protocol the tool prefers. Run two different methods before you trust either one.
Four one-line commands and what each asks
The common HTTP services return a plain-text address. One asks a web endpoint and prints whatever the server believes your source address to be. Another uses a DNS query, where the resolver sees the request without any HTTP layer involved.
On Windows, the same idea works through the built-in REST cmdlet, which returns a string rather than a full web page. On macOS and Linux, the command-line tools are already present, so nothing needs installing.
Each method answers a slightly different question. The HTTP service sees the address that reached it after any proxy or NAT, while the DNS method sees the address of the resolver’s query. When the two agree, you have a strong signal; when they disagree, the difference itself is informative.
Prefer the smallest response that answers the question. A plain-text endpoint returns one line, while a JSON endpoint returns the address alongside a city or provider name you did not ask for and should not trust for a decision.
IPv4 versus IPv6 with the same command
Most tools prefer whichever address family resolves first, which on a dual-stack connection can vary between runs. If you need a specific family, request it explicitly rather than reading whatever comes back.
A plain request over IPv6 will show the IPv6 address, which may look completely different from the IPv4 address the same machine uses. Both are correct; they are different paths to the same host.
If one family fails while the other succeeds, that is a routing problem worth investigating on its own. A lookup that silently falls back to IPv4 hides the failure, so test each family deliberately when something feels wrong.
Proxy variables that silently change the answer
Command-line tools honour proxy settings from the environment. A corporate laptop may have a proxy configured for terminal sessions, which means the request leaves through the proxy’s address rather than yours.
The result looks plausible and is completely wrong for the question you asked. A browser on the same machine may use a different proxy configuration, which is why the terminal and the lookup page disagree.
Clear the proxy variables for one run to see the direct answer, then restore them. If the direct run fails and the proxied run succeeds, the network requires the proxy and the address it reports is the one the outside world sees.
DNS-based lookups that bypass the browser
A resolver-based check sends a query to a public DNS service, which replies with the address it observed. There is no TLS, no HTTP headers, and no browser involvement, so it is useful for isolating a problem in the web path.
The answer reflects the resolver’s view, which is normally the same as the network’s egress. On a network that intercepts DNS, it may not be. If the DNS answer and the HTTP answer differ, you have found an interception point worth understanding.
Resolver checks are also fast and cache-friendly, which makes them convenient for a quick sanity check during a call. They are less useful for confirming what a specific application sees, because applications bring their own network paths.
Some networks block outbound queries to public resolvers, so the DNS method can fail while HTTP still works. A blank response is a clue about the network, not evidence that the connection has no address.
Running the check from a container or remote host
A container inherits the host’s egress in the default bridge setup, so the address it reports should match the host’s. In an overlay network or a cluster with an egress gateway, it will report the gateway instead.
This is exactly why the check is useful during deployment: run it inside the container and compare with the value on your laptop. A mismatch tells you the traffic is leaving through a different path than you assumed, which matters for any allowlist.
For remote servers, the check confirms which of the machine’s interfaces is used for outbound traffic. A host with several interfaces can have several public addresses, and the one that matters is the one the route selects.
Putting it in a script without breaking on errors
Wrap the call so that a timeout or a captcha response does not get recorded as an address. Validate the shape of the output before using it, and fail loudly if the value does not parse.
Do not hardcode the service into a critical path. Public lookup endpoints change ownership, rate-limit aggressively, and occasionally return an HTML error page with a 200 status. A script that trusts any 200 response will eventually store a paragraph of HTML as an address.
Log the method alongside the value. When an allowlist breaks six weeks later, knowing which endpoint produced the recorded address saves an hour of reconstruction.
Scripting the check safely
Pick one HTTP method and one DNS method, record both, and compare. Note the time, the interface, and whether a proxy was active, because those three facts explain nearly every disagreement between two runs.
For a one-off question, a what is my IP page is faster than a terminal. For anything that feeds a configuration file, use the command line and validate the output, since a stray newline in a whitelist entry is the kind of bug that costs an afternoon.


