Why do 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"?
Solution 1:
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.
Solution 2:
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 ;)