I'm trying to figure out how to obtain my external IP (IPv4) via Terminal without connecting to a remote website or service.

Here's what I've found so far - these all use remote/external checking:

  1. curl ifconfig.me
  2. curl icanhazip.com
  3. curl -s checkip.dyndns.org | grep -Eo '[0-9.]+'
  4. dig +short myip.opendns.com @resolver1.opendns.com

Is it even possible without checking some external source?

  • hostname -I works on my Linux servers.
    – HappyFace
    Feb 25 '21 at 20:42

It is not possible without checking an external source.

In a typical networking environment, nothing on your computer knows the external IP address the computer is using to communicate with the public internet. Instead, the computer has a private IP address and sends all traffic to the private IP address of a router which then forwards the traffic the the public internet using a public IP address.

The only reliable way to determine the public IP address associated with your computer's traffic is to contact an external source and have it tell you what IP address it sees your traffic coming from.


The external IP address you seek is really an arbitrary network router somewhere upstream of your connection, so your proposed solutions are all valid in needing an external device to confirm the external address.

If your Mac has a true routable internet address, then it is "external" already whether or not your routers use NAT or not.

To know about external routing details, you need to have access to the routers or to another computer that will run a traceroute or otherwise log the source IP address it needs to send responses to for the packets that originate from your Mac.


I don't think you can get an external IP without connecting to any external source as the IP Address you are looking for is not connected with your computer internally. External IP address is assigned to you by your Internet Service Provider. That is how the Internet and all other computers outside your local network see you. You can get this address by connecting to external source. I use IP-Details.com to check my external IP address mostly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .