4

I get different results for my IP when I type google "What is my IP" and when I type in macOS' terminal ifconfig |grep inet

Why are these results different on macOS version 10.13.2 High Sierra?

8

Unless your computer is directly connected to your ISP via the modem, your computer's IP address is actually assigned by your router (either provided by the ISP or yourself). The IP address you see when you go to a whatsmyip website is the public IP address that the ISP has assigned your router, which is the only IP address devices on the internet can talk to when trying to talk to a device on your network. Using a technique called Network Address Translation your router allows multiple devices (e.g. your laptop, your phone and your PlayStation) to share that single public facing IP address from your ISP among each of the devices.

Likely your devices connected to your internal network have IP addresses like 192.168.XXX.XXX or 172.16.XXX.XXX - 172.31.XXX.XXX or 10.XXX.XXX.XXX. These are Private IP addresses reserved for internal networks and are not usable on the wider internet.

7

The one you get from Google is your external address - your public one, which is actually assigned to the WAN (external) connection of your router by your ISP.

The one from ifconfig is your internal, private address - which is assigned from the LAN (internal) interface of your router.

You can use the caching utility to find your external, public IP address:

AssetCacheLocatorUtil 2>&1 | awk '/This.*public/{sub(/\.$/, ""); print $NF}'

Your router uses a structure known as NAT (Network Address Translation) so that packets destined for you are sent to the right computer, without exposing your internal address to the outside world.

Wikipedia link to Network Address Translation - which, honestly, you don't need to know & understand ;)

2

I loved the method using AssetCacheLocatorUtil, so I improved it just a bit by extracting only the IP from the string:

AssetCacheLocatorUtil 2>&1 | grep public | grep This | awk '{match($0,/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/); ip = substr($0,RSTART,RLENGTH); print ip}'
  • In this instance, there really is no good reason or practical need to double pipe the output of AssetCacheLocatorUtil thru grep and then to awk when the output of AssetCacheLocatorUtil can be processed all just by awk. If the system has a public IP address, then the following command returns just the public IP address, or nothing if not: AssetCacheLocatorUtil 2>&1 | awk '/This.*public/{sub(/\.$/, ""); print $NF}' – user3439894 Dec 22 '17 at 20:32

You must log in to answer this question.

protected by user151019 Dec 22 '17 at 17:15

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged .