Essential Mac Terminal Commands to Find Your IP Address

Updated

Mac IP address terminal command

The quickest way to find your IP address on a Mac is to hold the Option key and click the Wi-Fi icon in the menu bar. Your IP address and your router’s address appear under the network you’re connected to. For Ethernet, or for the full details, use System Settings. In Terminal, ipconfig getifaddr en0 prints the address by itself, as long as en0 is the connection you’re using.

These show your local address, the one your router assigned. Websites see your public address, covered below with the router and IPv6 addresses. The menu bar and System Settings steps apply to macOS 13 Ventura through macOS 27, and I ran the Terminal commands on macOS Tahoe 26.6.

Which IP address do you need?

Address What it is Fastest way to get it
Local IPv4 The private address your router assigned this Mac. Other devices on your network use it to reach the Mac. Option-click the Wi-Fi icon, or ipconfig getifaddr en0
Router (gateway) Your router’s address on your own network. Option-click the Wi-Fi icon, or route -n get default
Public IPv4 The one address all your devices share on the internet. It’s what websites see. curl https://checkip.amazonaws.com
IPv6 A separate set of addresses. A global one appears only if your network has IPv6. System Settings (Network, Details, TCP/IP), or ifconfig en0 inet6

Find your IP address in System Settings

  1. Choose Apple menu > System Settings, then click Network in the sidebar.
  2. Click the connection you’re using, such as Wi-Fi or Ethernet, then click Details.
  3. Click TCP/IP. It lists your IPv4 address, subnet mask and router address, plus your IPv6 address if the network provides one.

On macOS 12 Monterey and earlier, it’s System Preferences > Network: select the connection, click Advanced, then click TCP/IP.

No Wi-Fi icon in the menu bar? On macOS 26 and 27, go to System Settings > Menu Bar and select the Wi-Fi checkbox. On macOS 13 to 15, go to System Settings > Control Center and choose Show in Menu Bar next to Wi-Fi.

Find your IP address with Terminal commands

ipconfig getifaddr en0

This prints your IPv4 address and nothing else. Empty output means nothing is configured on en0: either you’re connected through a different interface, or your Mac has no address at all.

For everything about one connection, ask networksetup by service name:

networksetup -getinfo "Wi-Fi"

It shows the IP address, subnet mask, router and IPv6 settings. For a wired connection, run networksetup -listallnetworkservices to get the exact service name, and keep the quotes if it has spaces.

Why en0 isn’t always Wi-Fi

en0 is a BSD interface name, not a Wi-Fi label. On my MacBook Pro, which has no Ethernet port, Wi-Fi is en0, but Apple’s developer technical support says these names aren’t an API and carry no guarantees. Its own example is an Ethernet interface named en0. To see which name is which port on your Mac, run networksetup -listallhardwareports (the linked page covers ipconfig and ifconfig in depth). Each entry pairs a port with a device, such as Hardware Port: Wi-Fi and Device: en0.

Quicker still, ask macOS which interface carries your internet traffic:

route -n get default

Use the name on its interface: line in place of en0. If no interface has an address, or the only one starts with 169.254, your Mac didn’t get one from the router. macOS can assign itself a 169.254 address when DHCP fails, and that address only works on the local link. See MacBook Wi-Fi has no IP address for fixes.

Find your router’s IP address (default gateway)

System Settings shows it as the router address on the TCP/IP screen, and Apple notes that some ISPs call it the gateway address. In Terminal, either of these works:

route -n get default
netstat -rn -f inet

In the route output, the gateway: line is your router. In the netstat table, it’s the Gateway column on the line that starts with default. The -n flag skips looking up names for the addresses, and -f inet limits netstat to IPv4.

Find your IPv6 address

System Settings lists it on the TCP/IP screen when your network has IPv6. In Terminal:

ifconfig en0 inet6

You may see several inet6 lines, because one interface can hold several IPv6 addresses:

  • Starting with fe80: link-local. Every IPv6 interface has one, and it only works on your local network. Ignore it.
  • Starting with fd: a unique local address, used inside your network and not routed on the internet.
  • Starting with 2 or 3: a global address, the only range IANA currently assigns. macOS uses the one marked temporary by default for new connections, so that’s normally the IPv6 address websites see.

If you only see fe80 and fd lines, your Mac has no global IPv6 address on that network.

Find your public IP address

Behind a router, your Mac can’t see its public address. The router does network address translation: each device at home gets a private address (10.x.x.x, 172.16.x.x to 172.31.x.x and 192.168.x.x are reserved for this), and the router sends all their traffic out on the one address your ISP assigned. So you ask a server outside your network what address your request came from. Amazon and Cisco run these two, and both use them in their own documentation:

curl https://checkip.amazonaws.com
dig -4 +short myip.opendns.com @resolver1.opendns.com

The first is Amazon’s checkip service, which the AWS documentation suggests for this. It has only an IPv4 address, so it reports your public IPv4. The second asks Cisco’s OpenDNS over DNS instead of HTTP, which helps when curl is what’s broken, and it’s the same query Cisco’s Umbrella diagnostics run on Macs. The -4 keeps that query on IPv4, so the answer is your IPv4 address. Both print just the address, and they should match.

Your router’s status page also shows the IP address of its Internet (WAN) port. If that’s a private address, or falls between 100.64.0.0 and 100.127.255.255 (the range set aside for ISPs’ carrier-grade NAT), your ISP or another router in front of yours translates addresses again, and websites see that device’s address instead.

With iCloud Private Relay on, Safari sends your browsing through two relays, and sites see a temporary address from the second one instead of yours. Unless your ISP gave you a static address, it can also change, so look it up when you need it.

Because your public address can be used to estimate your location and profile you over time, I don’t paste it into public forums or bug reports unless someone needs it.

Photo of author
Sudhir P. founded HeatWare.com in 1999 and has built and operated it full-stack ever since; it is now used by more than 88,000 people. He writes here about the PostgreSQL, MySQL, Linux and DevOps work that keeps it running. Articles are rewritten only after the commands in them have actually been run, and the verification scripts are published alongside them so anyone can check the claims. Reach him at blog@heatware.net.