Get IP Address from Command Line

By  on  

Over the past few years I've needed to look up my IP address a dozen times.  What's funny is that I don't recall why I needed it, I just did.  So what's the easiest way to get my IP address from the command line?

To get your internal IP, you can do the following:

ipconfig getifaddr en0

I go through to get it:

curl ; echo

#  >>

Why go through an external resource?  Your local address and your external address aren't the same, so using the external resource is the best way to tell what the world is seeing your IP address as.

Recent Features

  • By
    Chris Coyier’s Favorite CodePen Demos

    David asked me if I'd be up for a guest post picking out some of my favorite Pens from CodePen. A daunting task! There are so many! I managed to pick a few though that have blown me away over the past few months. If you...

  • By
    Being a Dev Dad

    I get asked loads of questions every day but I'm always surprised that they're rarely questions about code or even tech -- many of the questions I get are more about non-dev stuff like what my office is like, what software I use, and oftentimes...

Incredible Demos


  1. ifconfig | grep mask
  2. ElanMan

    I prefer the slightly simpler/easier to remember

  3. nedt can give you even more information and is easier to use via tunneling as it works without a host header.

  4. MaxArt

    Windows users can use ipconfig (notice the ‘p’).

  5. Your internal IP also depends on interface you’re using, in your case (en0) it was ethernet, but it also can be WiFi (en1).

  6. ip route get | awk 'NR==1 {print $NF}'
  7. Some time ago I started using an alternative which only uses DNS queries:

    dig +short
  8. Google > “My IP” = Winner!

  9. $ curl
      "ip": "",
      "hostname": "",
      "city": "Orange",
      "region": "California",
      "country": "US",
      "loc": "33.7878,-117.8531",
      "org": "AS4323 tw telecom holdings, inc.",
      "postal": "92666"
    $ curl
    $ curl
    AS4323 tw telecom holdings, inc.

    See for more details

  10. I just search Google for “what is my ip” like a n00b.

  11. I prefer:

    alias publicip='curl ; echo'
    alias localip="ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v ''"
  12. hahaha, i just think to google it :D, but thanks dude, sometimes need to apply to my terminal command

  13. It is ugly. But the Google lovers will enjoy.

    Prerequisite: curl, and grep.

    curl -s "" | grep "Client IP address" | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b"

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!