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?
Ask Different is a question and answer site for power users of Apple hardware and software. It only takes a minute to sign up.
Sign up to join this communityI 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?
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.
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 ;)
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}'
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