The quickest Mac Terminal command to find your IP address is:
ipconfig getifaddr en0
On a MacBook Air (and most Wi-Fi-only Macs), en0 is the Wi-Fi interface, so this prints your local IP, such as 192.168.1.23. For the public IP that websites see, run curl -4 -s https://ifconfig.me. Both commands were tested on a MacBook Air running macOS Tahoe 26.6.2. In every output below, the real addresses are swapped for example ones.
Get your local IP with ipconfig
ipconfig getifaddr en0
192.168.1.23
That’s it. One line, no extra text, so it’s easy to use in scripts:
MYIP=$(ipconfig getifaddr en0)
echo "My IP is $MYIP"
Here is a gotcha worth knowing. If you ask for the wrong interface, ipconfig prints nothing. There’s no error message. It just exits with code 1:
ipconfig getifaddr en1; echo "rc=$?"
rc=1
On my MacBook Air, en1 is a Thunderbolt port, not Wi-Fi, so it has no address. On a Mac with a built-in Ethernet port (an iMac, Mac mini or Mac Studio), en0 is usually Ethernet and Wi-Fi is often en1. So if you get a blank line, the next step is to find out which interface you’re actually using.
Find which interface is active (en0, en1…)
Ask the routing table which interface carries your default route:
route -n get default | grep interface
interface: en0
To see what every name means, list the hardware ports:
networksetup -listallhardwareports
Hardware Port: Ethernet Adapter (en3)
Device: en3
Ethernet Address: aa:bb:cc:00:00:03
Hardware Port: Ethernet Adapter (en4)
Device: en4
Ethernet Address: aa:bb:cc:00:00:04
Hardware Port: Thunderbolt Bridge
Device: bridge0
Ethernet Address: aa:bb:cc:00:00:10
Hardware Port: Wi-Fi
Device: en0
Ethernet Address: aa:bb:cc:00:00:01
Hardware Port: Thunderbolt 1
Device: en1
Ethernet Address: aa:bb:cc:00:00:11
Hardware Port: Thunderbolt 2
Device: en2
Ethernet Address: aa:bb:cc:00:00:12
VLAN Configurations
===================
On this MacBook Air, Wi-Fi is en0, the two Thunderbolt ports are en1 and en2, and en3/en4 show up as “Ethernet Adapter” even with nothing plugged in. If you use a USB-C Ethernet dongle, it will get its own enX name and show up in this list once connected.
You can combine the two steps so the command works on any Mac:
ipconfig getifaddr "$(route -n get default | awk '/interface/ {print $2}')"
192.168.1.23
Show all IP addresses with ifconfig
ifconfig dumps every interface. Filter it to lines with an IPv4 address:
ifconfig | grep "inet "
inet 127.0.0.1 netmask 0xff000000
inet 192.168.1.23 netmask 0xffffff00 broadcast 192.168.1.255
The space after inet matters. Without it, grep inet also matches every inet6 line. The 127.0.0.1 line is the loopback address. Every Mac has it, and it’s only reachable from the Mac itself. The netmask 0xffffff00 is hex for 255.255.255.0. You can get the same thing in plain decimal with:
ipconfig getoption en0 subnet_mask
255.255.255.0
Find your router (gateway) IP
The gateway is the router your Mac sends traffic through:
route -n get default | grep gateway
gateway: 192.168.1.1
Two other ways give the same answer:
ipconfig getoption en0 router
netstat -rn -f inet | grep default
192.168.1.1
default 192.168.1.1 UGScg en0
Type that address into a browser to reach your router’s admin page. Don’t assume it ends in .1, though. On my test network the router’s address ended in a different number, which is common with phone hotspots and some mesh systems.
Find your public IP address
Your local IP is only valid inside your network. Websites see a different, public address that belongs to your router or your ISP. To see it, ask an outside service:
curl -s https://ifconfig.me
curl -s https://api.ipify.org
This is where I hit the most useful surprise of this test. The two commands returned different kinds of addresses:
2001:db8:1234:5678:4519:a393:5c9e:f6a
203.0.113.46
ifconfig.me returned an IPv6 address, because my network has IPv6 and curl prefers it. api.ipify.org only answers over IPv4, so it returned an IPv4 address. If a guide tells you to expect something like 203.0.113.45 and you get a long string with colons, nothing is broken. Force IPv4 with -4:
curl -4 -s https://ifconfig.me
203.0.113.45
Look closely and you’ll see the second surprise. ifconfig.me -4 and api.ipify.org gave two different IPv4 addresses seconds apart. My test Mac was on a mobile carrier’s network, which shares a pool of public IPs among many users (this is called carrier-grade NAT). Each new connection can leave from a different address. On a normal home connection both services should agree. If they don’t, you’re probably behind a carrier NAT or a VPN, and you can’t host a server on that public IP.
Add ; echo at the end if the IP runs into your next prompt. I checked the raw bytes: neither ifconfig.me nor api.ipify.org sends a trailing newline.
IPv6 addresses
To list IPv6 addresses on Wi-Fi:
ifconfig en0 | grep inet6
inet6 fe80::1c2b:3d4e:5f60:7a8b%en0 prefixlen 64 secured scopeid 0xb
inet6 2001:db8:1234:5678:187b:5aca:e995:59b7 prefixlen 64 autoconf secured
inet6 2001:db8:1234:5678:4519:a393:5c9e:f6a prefixlen 64 autoconf temporary
There are three:
fe80::…is link-local. It only works on your local network segment.securedis a stable address for this network.temporaryis a privacy address that macOS rotates over time. This is the one websites see. Notice it matches whatifconfig.mereturned above.
Note that ipconfig getifaddr is IPv4 only. I tried ipconfig getv6ifaddr en0 and it doesn’t exist. ipconfig just prints its usage list. Use ifconfig en0 | grep inet6 instead.
Private vs public IP: which one do you need?
| Private (local) IP | Public IP | |
|---|---|---|
| Example | 192.168.1.23 | 203.0.113.45 |
| Command | ipconfig getifaddr en0 | curl -4 -s https://ifconfig.me |
| Who sees it | Devices on your Wi-Fi | Every website and server you visit |
| Changes when | You rejoin the network or DHCP renews | Your ISP reassigns it, or each connection on carrier NAT |
| Use it for | SSH between your own machines, testing a dev server on your phone, printer setup | Allow-lists, remote access, support tickets |
Private addresses always fall in three ranges: 10.x.x.x, 172.16.x.x–172.31.x.x, and 192.168.x.x. If your “IP” starts with one of those, it’s private.
A common use: you run a dev server on your Mac and want to open it from your phone. Use the private IP plus the port, like http://192.168.1.23:3000. If the port is already taken by an old process, see how to kill a process on a port on Mac.
Common questions
Why does ipconfig getifaddr en0 print nothing?
Either en0 isn’t your active interface or you’re not connected. Run route -n get default | grep interface to get the right name, then try again with that name.
Is there a single command that works on every Mac?
Yes, the combined one above: ipconfig getifaddr "$(route -n get default | awk '/interface/ {print $2}')". It looks up the active interface first, so it works for Wi-Fi, Ethernet, or a USB adapter.
Why is my public IP different on two websites?
Either one site returned IPv6 and the other IPv4, or you’re behind carrier-grade NAT, where each connection can use a different public address. Use curl -4 on both to compare IPv4 to IPv4.
Does a VPN change these results?
The public IP should show the VPN server’s address, while the local en0 IP stays the same. VPNs typically use a utunX interface, but don’t count interfaces to spot it: ifconfig -l on my test Mac already listed utun0 through utun9 with no VPN running. Look for the utun that has an inet line. (I didn’t test with a VPN for this post.)
My DNS seems wrong after I changed networks. What now?
Check your DNS servers with scutil --dns and clear the cache. See how to flush DNS on Mac.