How to Find Your IP Address on Mac Using the Command Line

Posted: | Tags: Mac

This article explains how to find your private (local) and public IP addresses on a Mac using the command line.

If you're using Windows, see the following article for instructions:

Find your private IP address

You can find your private IP address by specifying a network interface with the ipconfig getifaddr command.

On most Macs, the Wi-Fi interface is typically named en0, so you can run:

$ ipconfig getifaddr en0
192.168.XXX.XXX

To see more detailed network information, use the ifconfig command:

$ ifconfig en0
...

If you're using a wired connection, the interface name may be different. In that case, replace en0 with the correct name.

You can list all network interfaces using the networksetup -listallhardwareports command:

$ networksetup -listallhardwareports
Hardware Port: Wi-Fi
Device: en0
Ethernet Address: XX:XX:XX:XX:XX:XX

Hardware Port: Thunderbolt 1
Device: en1
Ethernet Address: XX:XX:XX:XX:XX:XX

...

Look for the Device value that corresponds to the network you're connected to, and use that with ipconfig or ifconfig as needed.

Find your public IP address

There are several websites that will show your public IP address when accessed. One example is a site provided by AWS:

You can retrieve your public IP from the terminal using curl:

$ curl checkip.amazonaws.com
XXX.XXX.XXX.XXX

Note that checkip.amazonaws.com returns the IP address from the X-Forwarded-For header if it is present, which can result in an inaccurate reading of your actual public IP address, especially in testing scenarios.

$ curl checkip.amazonaws.com --header "X-Forwarded-For: 0.0.0.0"
0.0.0.0

If you need a service that ignores the X-Forwarded-For header, consider using the following:

$ curl ifconfig.io
XXX.XXX.XXX.XXX
$ curl ifconfig.io --header "X-Forwarded-For: 0.0.0.0"
XXX.XXX.XXX.XXX

Related Categories

Related Articles