Your Mac has two addresses that people call “my IP”. The public one is what websites and servers see. The local one is what your router gave the Mac inside your network. Terminal shows both, each with a different command.
Commands tested on macOS 27.0.1 on 2026-10-20. Addresses and names in the output are replaced.
Public or local: which one you need
| Public IP | Local IP | |
|---|---|---|
| Who gives it out | Your internet provider, to your router | Your router, to the Mac |
| Who sees it | Every website and server you connect to | Only devices on your own network |
| Shared? | Yes, for IPv4: every device at home goes out with it | No: each device has its own |
| Typical look | 203.0.113.45 |
192.168.1.23, 10.0.0.5 |
| Terminal command | curl https://ifconfig.me |
ipconfig getifaddr en0 |
You need the public address to allow your home in a server’s firewall, to check a VPN, or to tell support what the internet sees. You need the local one to reach the Mac from another device at home.
The public address is not always your router’s own. If your router lists its own outside address as 100.64.x.x to 100.127.x.x, your provider shares one public address among many customers (carrier-grade NAT). The commands below then print that shared address, not the router’s. IP addresses explains private ranges and NAT in more detail.
Find your public IP in Terminal with curl
The public address is the one your provider gives your router, not the Mac. To learn it, ask a server on the internet which address your request came from.
- Open Terminal (Applications › Utilities).
- Run:
curl https://ifconfig.me
203.0.113.45
That is your public IP address. ifconfig.me sends no line break after the address, so it sits right in front of the next prompt. Add ; echo to put the prompt on its own line:
curl https://ifconfig.me; echo
In a browser, ifconfig.me shows a web page. To curl it answers with the bare address, which is what makes it handy in Terminal and in scripts.
Other services answer the same way. All of these printed the same address on the test Mac:
| Command | Output | Notes |
|---|---|---|
curl https://ifconfig.me |
203.0.113.45 |
No line break at the end |
curl https://api.ipify.org |
203.0.113.45 |
No line break at the end |
curl https://icanhazip.com |
203.0.113.45 |
Ends with a line break |
curl -s https://1.1.1.1/cdn-cgi/trace |
Several lines, one of them ip=203.0.113.45 |
Cloudflare’s diagnostic page |
To keep the address in a shell variable, use the form from ipify’s own documentation:
ip=$(curl -s https://api.ipify.org); echo "Public IP: $ip"
Public IP: 203.0.113.45
Each of these is a third-party service. It sees your address anyway, because that is how the answer works, but pick one you trust and use https://.
IPv4 and IPv6
A connection can have a public IPv4 address and a public IPv6 address at the same time. Ask for each one on purpose:
curl -4 https://ifconfig.me; echo
curl -6 https://api6.ipify.org
-4 and -6 tell curl to use only IPv4 or only IPv6. The ; echo keeps the two answers on separate lines. ipify runs api6.ipify.org for IPv6 only, and says that “if you don’t have an IPv6 address, the request will fail.” The test network has no IPv6, so the second command failed:
203.0.113.45
curl: (6) Could not resolve host: api6.ipify.org
On a network with IPv6, the second line is an IPv6 address instead, in the form 2001:db8::45 (an example address).
Note: Don’t test IPv6 with
curl -6 https://ifconfig.me. On the test Mac, with no IPv6 at all, it still printed the IPv4 address. macOS answered the IPv6-only lookup with a “mapped” IPv4 address (::ffff:34.160.111.145incurl -6 -voutput), and the curl manual warns that “macOS is known to do this.” A hostname that has only an IPv6 address, such asapi6.ipify.org, gives an honest answer.
Find your public IP with dig
dig is built into macOS. Some DNS servers answer a special name with the address your query came from, so you get your public IP without a website. These three printed the same address on the test Mac:
dig +short myip.opendns.com @resolver1.opendns.com
dig +short TXT o-o.myaddr.l.google.com @ns1.google.com
dig +short CH TXT whoami.cloudflare @1.1.1.1
203.0.113.45
"203.0.113.45"
"203.0.113.45"
@ names the DNS server to ask, and +short prints only the answer. Google’s and Cloudflare’s answers are text records, so they come in quotes. Cloudflare’s name lives in the CH (Chaosnet) class rather than the usual IN, which is why the command names it: asked in IN, the same name returned NXDOMAIN (no such name) on the test Mac. To drop the quotes:
dig +short TXT o-o.myaddr.l.google.com @ns1.google.com | tr -d '"'
On the test Mac, which has no IPv6, all three returned the IPv4 address. For IPv6, use the curl command in the previous section.
Find your local IP: ipconfig getifaddr en0
The local address comes from the Mac itself, so no outside service is involved:
ipconfig getifaddr en0
192.168.1.23
The manual says this prints “the IP address for the first network service associated with the given interface”, and that the output “will be empty if no service is currently configured or active on the interface.”
en0 is an interface name, and it is not the same on every Mac. On the test Mac, a laptop, en0 is Wi-Fi and en1 is a Thunderbolt port, so ipconfig getifaddr en1 printed nothing. To see which name belongs to which port:
networksetup -listallhardwareports
Hardware Port: Wi-Fi
Device: en0
Ethernet Address: aa:bb:cc:dd:ee:ff
Hardware Port: Thunderbolt 1
Device: en1
Ethernet Address: aa:bb:cc:dd:ee:ff
(Shortened. The test Mac also listed Thunderbolt 2 and 3, a Thunderbolt Bridge, and three Ethernet adapters as en4 to en6.)
If you are not sure which interface carries your traffic, route -n get default names it on its interface: line (interface: en0 here). Put that name in place of en0.
In Netutilus, Network Monitor lists every interface with its addresses and marks the one in use. It is free.
Why the answer changes with a VPN or iCloud Private Relay
Your public address is the one your traffic leaves through. Two things on a Mac can change it.
A VPN. With the VPN on, the commands above should print the VPN server’s address, and a lookup of it shows the VPN provider and the server’s country. If you still see your provider’s address, the VPN is not carrying your traffic. Compare both families too: a VPN that carries only IPv4 lets IPv6 traffic go around it with your real address, so curl -4 and curl -6 can name two different networks. Split-tunnel VPNs, such as Tailscale and most company VPNs, send ordinary traffic outside the tunnel on purpose, so they leave your public address as it was. Is my VPN working? walks through the checks.
iCloud Private Relay. Apple lists what Private Relay covers: “web browsing in Safari, DNS resolution queries, and insecure http app traffic.” Its second relay, run by a third-party provider, gives that traffic a temporary IP address. A curl https:// command in Terminal is not on that list, so Terminal and a “what is my IP” site in Safari can show two different addresses while Private Relay is on. Apple also notes that most location databases label these addresses with the organization “iCloud Private Relay”.
| What you see | Likely reason |
|---|---|
| Terminal and Safari show different public addresses | iCloud Private Relay is on and covers Safari |
curl -4 and curl -6 show different providers or countries |
A VPN carries one address family only |
| The address belongs to your VPN provider | The VPN works for that traffic |
| The address stays the same with the VPN on | A split-tunnel VPN, or the VPN is not carrying traffic |
Keep it visible: public IP and country in the menu bar
Typing a command works when you need the address once. If you check it often, for a VPN or a server allowlist, the Netutilus menu bar item keeps it one click away. The menu bar item and GeoIP are free.
- Open Netutilus. Its item appears in the menu bar.
- Click the item. The top shows the country and city of your public address, the address itself, an IPv6 address if the Mac has one, and the provider.
- Click the address to copy it.
- Read the status line below it: VPN · on with the tunnel interface’s name in brackets, or VPN · off.
- To keep the country in the menu bar itself, open Settings › Menu Bar and set Label text to Flag or Flag and country code.
- To hear about changes, turn on Notify when the public IP changes or Notify when the VPN connects or drops in the same pane.
Clicking the country opens GeoIP, which shows the address’s provider, AS number and approximate location. Its My IP button looks up your own address at any time.
The app finds the address the same way the commands above do: it asks a lookup service. The Menu Bar settings say when: at launch, when the network changes and every 15 minutes, at ipwho.is with ipapi.co as a fallback.
When Terminal is the better choice
- Scripts and remote sessions.
curl -s https://api.ipify.orgworks in a script, over SSH, and on a Mac where you cannot install apps. - DNS instead of a website. The dig commands ask the OpenDNS, Google or Cloudflare name servers, not a web page.
- IPv6 on demand.
curl -6 https://api6.ipify.organswers the IPv6 question directly and fails clearly when there is no IPv6.
For a quick reference, these are the commands from this page:
| Task | Command |
|---|---|
| Public IPv4 | curl -4 https://ifconfig.me |
| Public IPv6 | curl -6 https://api6.ipify.org |
| Public IP over DNS | dig +short myip.opendns.com @resolver1.opendns.com |
| Local IP | ipconfig getifaddr en0 |
| Which interface is in use | route -n get default |