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.
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:
- Create a new folder called “ip” at the Web root directory
- Create a file called “index.php” with the following contents:
<?php echo $_SERVER['REMOTE_ADDR']; echo "\n" ?>
- 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:
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.
How to change the public IP on FTTH?
Your public IP address is typically assigned to you by your Internet Service Provider. Speak to them about changing your address.