Determine your Mac’s public IP address

NetworkIconX There are plenty of reasons why you might wish to look up your current public IP address; whether it is to check some logged connection, or to troubleshoot some connectivity issue.

If your Mac has been given a public IP address by the network that it is on, then you can look this up in the current active connection in the Network system preferences, and use several different Terminal commands to find this at the command line; however, in most cases this address is stored in your network’s router, which in turn issues separate private IP addresses for your Mac and other devices that this router manages.

This setup provides a degree of separation that allows better security for your Mac from internet traffic; however, it also prevents your Mac from directly knowing its public IP address, as it will only have a record of the private one being issued to it.

As a result, if you would like to look up your public IP address, you will need to use an external service that will log the IP address and return it to you.

There are many Web resources for doing exactly this, and you can simply search Google for “IP” to have it be reported to you, or visit one of many network information sites like whatismyip.com to confirm your IP address.

In addition to accessing these services on the Web, you can do so from the Terminal in the event you wish to get your IP address when creating scripts. In most cases, you can simply use the terminal-based “curl” command to access these same Web resources and get your IP address, some of which are the following:

curl ifconfig.me
curl canhazip.com
curl ip.appspot.com
curl ipecho.net/plain; echo
curl checkip.dyndns.org

In some cases the formatting of these is slightly different than a simply text string of your IP address, so when scripting you may have to manage carriage returns or perhaps XML code returned by the “curl” command, but they should be relatively useful.

While these options are easy to use, they do rely on a third-party server being up and running, and configured to return your IP address to you. Since Web content and servers can be changed and reconfigured at any time, if you have your own Web host then you might consider simply creating your own page to look up your IP address using the curl command.

To do this, you simply need a Web host with PHP enabled:

  1. Create a new folder called “ip” at the Web root directory
  2. Create a file called “index.php” with the following contents:
    <?php echo $_SERVER['REMOTE_ADDR']; echo "\n" ?>
  3. Save the file and exit

Now you can point your browser to this address and the server will report back your current public IP address, or use the “curl” command in the Terminal to load the same location and be able to add this to scripts. As an example, I have created one here at MacIssues, so the following URL and Terminal commands should return your public IP:

https://macissues.com/ip/

curl macissues.com/ip/

3 thoughts on “Determine your Mac’s public IP address

  1. Chris Hart

    On my portable Macs, I keep IPBroadcaster from 10Base-T Interactive in my toolbar. It gives me both my LAN and WAN addresses at a glance. It’s free and very handy.
    http://10base-t.com/macintosh-software/ip-broadcaster/

    1. Chris Hart

      Your public IP address is typically assigned to you by your Internet Service Provider. Speak to them about changing your address.

Comments are closed.