Ask Dave Taylor
  • Facebook
  • Instagram
  • Linkedin
  • Pinterest
  • Twitter
  • YouTube
  • Home
  • YouTube Videos
  • Top Categories
  • Subscribe via Email
  • Ask A Question
  • Meet Dave
  • Home
  • Mac & MacOS Help
  • How do I figure out my IP address on a Mac?

How do I figure out my IP address on a Mac?

April 12, 2005 / Dave Taylor / Mac & MacOS Help / 29 Comments

Dave, as far as I know, I get a new IP address every time I connect to the Internet with my Apple PowerBook. How do I figure out what address I’ve been assigned?

If you’re running Dynamic Host Configuration Protocol (DHCP) then you’re right, you’ll get a new IP address (possibly recycled) each time you connect to the Internet. Well, you actually get what’s called a “lease”, so you only get a new address when your lease expires. Typically DHCP servers are configured to give 24 hour leases, so it’s not quite as much a moving target.

The easiest way to identify your IP address is to pop open the Terminal (go to Applications -> Utilities -> Terminal) and type in the interface configuration (ifconfig) command.

There are some utilities and apps you can use, and for that matter you can also go to “System Preferences…” off the Apple menu and look at your “Network” panel, but let’s stick with “ifconfig” because it’s a bit more interesting to use the command line…

$ ifconfig
lo0: flags=8049 mtu 16384
inet6 ::1 prefixlen 128
inet6 fe80::1 prefixlen 64 scopeid 0x1
inet 127.0.0.1 netmask 0xff000000
gif0: flags=8010 mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8863 mtu 1500
ether 00:30:65:3d:e8:10
media: autoselect ()
supported media: none autoselect 10baseT/UTP ...
en1: flags=8863 mtu 1500
inet6 fe80::230:65ff:fe03:25bc prefixlen 64 scopeid 0x5
inet 10.0.0.104 netmask 0xffffff00 broadcast 10.0.0.255
ether 00:30:65:03:25:bc
media: autoselect status: active
supported media: autoselect
fw0: flags=8822 mtu 2030
lladdr 00:30:65:ff:fe:3d:e8:10
media: autoselect  status: inactive
supported media: autoselect 

The number you want to identify is immediately after the “inet” field. Rather than just scan this visually, however, let’s use some Unix commands to extract the data we want.

The first command we’ll use is grep, a simple pattern matching filter. We’ll make what Unix geeks call a “pipe” by separating the two commands with the “|” symbol, which causes the output of the first command to be fed to the second command as its input. Put them together:

$ ifconfig | grep "inet"
inet6 ::1 prefixlen 128
inet6 fe80::1 prefixlen 64 scopeid 0x1
inet 127.0.0.1 netmask 0xff000000
inet6 fe80::230:65ff:fe03:25bc prefixlen 64 scopeid 0x5
inet 10.0.0.104 netmask 0xffffff00 broadcast 10.0.0.255

A lot better already! Now, let’s narrow it down to just the “inet” fields, not the “inet6” (which is actually IPv6, but that’s beyond the scope of this discussion) by adding a space to the pattern:

$ ifconfig | grep "inet "
inet 127.0.0.1 netmask 0xff000000
inet 10.0.0.104 netmask 0xffffff00 broadcast 10.0.0.255

Almost done. The second line has the real IP information for my computer because the IP address 127.0.0.1 is special, it’s called your “loopback” address and always refers to your own computer, regardless of if you are running a Mac, PC, Linux or any other sort of machine. Just part of the definition of the underlying TCP/IP protocol.

To get rid of that spurious match, I’ll use grep again, but this time I’ll include the ‘-v’ flag, which reverses the logic of the search (that is, it’ll match all lines that do not match the specified pattern):

$ ifconfig | grep "inet " | grep -v 127.0.0.1
inet 10.0.0.104 netmask 0xffffff00 broadcast 10.0.0.255

That’s short and sweet. One more step, just a little one, to remove the stuff we don’t really care about in the output, okay? For this, I’m going to use cut, a great command line utility, to show me just the second field in the line, using spaces as a delimiter:

$ ifconfig | grep "inet " | grep -v 127.0.0.1 | cut -d\  -f2
10.0.0.104

Perfect! Now, final step, save this as a Bash alias by typing in the following (exactly):

$ echo 'alias myip="ifconfig | grep 'inet ' | grep -v 127.0.0.1 | cut -d\   -f2"' >> ~/.bashrc

Exit your Terminal window and launch a new one, and from this time forward you’ll always be able to simply type myip to find out what your current IP address is, all within the terminal!

Hope this helps you out!

About the Author: Dave Taylor has been involved with the online world since the early days of the Internet. Author of over 20 technical books, he runs the popular AskDaveTaylor.com tech help site. You can also find his gadget reviews on YouTube and chat with him on Twitter as @DaveTaylor.

Let’s Stay In Touch!

Never miss a single article, review or tutorial here on AskDaveTaylor, sign up for my fun weekly newsletter!
Name: 
Your email address:*
Please enter all required fields
Correct invalid entries
No spam, ever. Promise. Powered by FeedBlitz
Please choose a color:
Starbucks coffee cup I do have a lot to say, and questions of my own for that matter, but first I'd like to say thank you, Dave, for all your helpful information by buying you a cup of coffee!

29 comments on “How do I figure out my IP address on a Mac?”

  1. yui says:
    April 15, 2013 at 5:52 am

    Thank you for your help with this. It’s a little task, but nice to know how to do it correctly when I need my IP address.

    Reply
  2. Dave Taylor says:
    May 6, 2012 at 8:32 am

    Sam, did you add the line
    alias myip=”ifconfig | grep ‘inet ‘ | grep -v 127.0.0.1 | cut -d\ -f2″
    to your ~/.profile or ~/.bashrc, then quit your Terminal window and open up a new one?

    Reply
  3. Sam says:
    May 6, 2012 at 8:16 am

    I keep on trying but it always says, -bash: myip: command not found. Any help?

    Reply
  4. Dave Taylor says:
    September 15, 2011 at 1:52 pm

    Ah, I understand now, Tom. The problem is that what the shell’s seeing is:
    alias myip=ifconfig
    then the rest of it is a command it actually executes, which is definitely wrong. Add double quotes, one before “ifconfig” and one after “-f2” — in the .bashrc — and see if that works better. 🙂

    Reply
  5. Tom says:
    September 15, 2011 at 10:50 am

    $ tail -5 ~/.bashrc
    alias myip=ifconfig | grep ‘inet ‘ | grep -v 127.0.0.1 | cut -d\ -f2

    Reply
  6. Dave Taylor says:
    September 14, 2011 at 11:04 pm

    Tom, what do you get when you do this:
    tail -5 ~/.bashrc
    and I admit, the command to see all the aliases is “alias”, not “aliases” as I suggested earlier. If only I could edit these darn comments! 🙂

    Reply
  7. Tom says:
    September 14, 2011 at 12:46 pm

    Still no go…
    shoeis-computer:~ shoei$ . ~/.bashrc
    shoeis-computer:~ shoei$ aliases
    -bash: aliases: command not found
    shoeis-computer:~ shoei$ . .bashrc
    shoeis-computer:~ shoei$ aliases
    -bash: aliases: command not found
    shoeis-computer:~ shoei$ alias
    shoeis-computer:~ shoei$ ifconfig | grep ‘inet ‘ | grep -v 127.0.0.1 | cut -d\ -f2
    180.168.10.54
    shoeis-computer:~ shoei$

    Reply
  8. Dave Taylor says:
    September 14, 2011 at 11:16 am

    That’s all correct, Tom. Either log out and log in again to your Terminal window (xterm, etc) or you have to force the shell to interpret the new rc file *within its own process*. By just using something like “sh .bashrc” you spawn a subshell, that processes the new alias, then the subshell is killed because it’s done with its work.
    Instead, try this:
    . .bashrc
    or, if that complains it can’t find the rc file:
    . ~/.bashrc
    Now type
    aliases
    and you should see “myip” show up.

    Reply
  9. Tom says:
    September 14, 2011 at 10:24 am

    Running OS10.6.8
    shoeis-computer:~ shoei$ echo alias myip=”ifconfig | grep ‘inet ‘ | grep -v 127.0.0.1 | cut -d\ -f2″ >> ~/.bashrc
    shoeis-computer:~ shoei$ myip
    -bash: myip: command not found
    shoeis-computer:~ shoei$ cat .bashrc
    alias myip=ifconfig | grep ‘inet ‘ | grep -v 127.0.0.1 | cut -d\ -f2
    shoeis-computer:~ shoei$ vi .bashrc
    (I removed the blank first line)
    shoeis-computer:~ shoei$ myip
    -bash: myip: command not found
    shoeis-computer:~ shoei$

    Reply
  10. brainbashing says:
    December 28, 2010 at 6:13 pm

    @dave taylor
    he echo’ed the command so it will be appended (that’s what >> is all about) to the .bashrc configuration file that the alias will load every time you use the command line. If you only type alias name=”command -flag -flag | pipe | pipe” you will just set the alias for the current session.
    I am even using a different approach (I have a fairly frequent use of aliases) in importing the aliases from another file so it won’t clutter the .bashrc file. I called it .bash_aliases and import it with the following lines (I add to the .bashrc or .bash_profile):
    if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
    fi
    This will cause the file .bash_aliases being loaded (if it exists) every time .bashrc or .bash_profile is executed.
    you can also add the alias to the .bashrc or .bash_profile with opening the desired file with nano, and editing it directly:
    nano ~/.bashrc

    Reply
  11. dennis bracamonte says:
    November 21, 2010 at 11:49 am

    $ echo alias myip=”ifconfig | grep ‘inet ‘ | grep -v 127.0.0.1 |
    cut -d\ -f2″ >> ~/.bashrc
    this command does not work
    $ alias myip=”ifconfig | grep ‘inet ‘ | grep -v 127.0.0.1 |
    cut -d\ -f2″ >> ~/.bashrc
    but this one does!
    i dont know why he had echo? but remove it and type excactly this and it should work.
    alias myip=”ifconfig | grep ‘inet ‘ | grep -v 127.0.0.1 |
    cut -d\ -f2″ >> ~/.bashrc

    Reply
  12. Dave Taylor says:
    July 27, 2010 at 9:44 am

    Darin, if you don’t to create an alias for “myip” then you don’t have to worry about it, otherwise you’ve got your quotes wrong OR you’re typing this in on two lines. 🙂

    Reply
  13. Darin Marshall says:
    July 21, 2010 at 4:06 pm

    Everything worked as described in this article except this part:
    echo alias myip=”ifconfig | grep ‘inet ‘ | grep -v 127.0.0.1 |
    cut -d\ -f2″ >> ~/.bashrc
    When I did this, typing myip returned:
    -bash: myip: command not found
    Is this related to the path to bash?

    Reply
  14. Thul Dai says:
    May 27, 2010 at 4:17 am

    Thanks, extremely useful!
    Although John Bales’ hint (2nd commentary) might beat yours out in simplicity…

    Reply
  15. LEBATO says:
    April 20, 2010 at 5:03 pm

    Ok, I don’t know why you have to make it so hard for people new to IPs. For those asking about having two different IPs. Your address in 10.x.x.x or 192.x.x is your private address. It is what your home dsl box, router, or cable modem gives you. To go out on the internet you need a different kind of IP address, one that isn’t private, but public.
    Your public address is what whatismyip.com will show you, this is 99% of the time not the address of your computer, but the address your router/dsl/cable modem has.
    Public addresses are unique, no two are the same at the same time. Private addresses can repeat (for example, your friend might have the exact same ip address on his PC, but never the same public address).
    Anyways, cool article author!

    Reply
  16. Dave Taylor says:
    November 26, 2009 at 12:16 pm

    fif, most likely what’s happening is that you have a router or gateway that’s also acting as a NAT and DHCP server. That is, the box is protecting your individual machines from the Internet by mapping all of your internal addresses (for multiple machines, for example) into a single address. That’s usually 192.* and it’s all normal. Basically you can just use the router’s address (what whatismyip.com reports) and you should be fine.

    Reply
  17. fif says:
    November 26, 2009 at 1:25 am

    Hi Dave and Anonymuss,
    I have the same problem than Anonymuss.
    When i get my IP address with your command i get something like: 192.168.etc
    And when I check with what http://www.whatismyip.com or http://www.ip-details.com gives, I get something like 79.85.etc.
    Why is it different? Shouldn’t I get the ame result?
    Cheers

    Reply
  18. Anonymuss says:
    November 21, 2009 at 6:14 pm

    Well Dave, I followed your directions in the Terminal and while the grep command is nifty, I not sure your instructions yield a user’s actual IP address. In my case, I also got the 10.0.X.X result, and this is confirmed in the Network Utility application’s Info tab. But my actual IP address apparently begins with 75. This is confirmed with the URLs provided by Erika and Madhu, and by simply editing in Wikipedia without logging in (they capture and display it). So, I’m confused now — are there two IP addresses?

    Reply
  19. Dave Taylor says:
    July 26, 2009 at 12:08 am

    Sure, Willa. IP = Internet Protocol. It’s the bottom part of “TCP/IP” (TCP = Transmission Control Protocol). As I understand it, IP relates to how information is sent point-to-point from one computer to another on the network, and TCP is how that information is “packaged up” for transmission and receipt. So IP is like a phone line, while a fax machine’s message is like TCP.

    Reply
  20. willa says:
    July 24, 2009 at 10:28 am

    Could you please just explain in two sentences or less what an IP address is? I am getting a notice everyday that I must upgrade my IP address

    Reply
  21. madhu says:
    July 23, 2009 at 1:09 am

    Thanks for the information about the ip address I know my own ip address from the site http://www.ip-details.com

    Reply
  22. Kimberley says:
    March 3, 2009 at 9:00 pm

    I am getting emails from a cyberstalker…. I have a restraining order against him and he continues to violate the restraining order. How do I find the ip address of the location of where he is sending these emails from ? and how do I trace the email address that he is using back to his orginal email address which has his information all over it???

    Reply
  23. Jasmine says:
    January 28, 2009 at 5:43 pm

    my aautomatic ip address,dns won’t work how do i make it work.do i go to manual ip address and dns and make one? its for my psp…please help me!!!

    Reply
  24. michael m. says:
    March 12, 2007 at 6:02 pm

    dave, on my PSP my IP address times out…. so I type it in manually, but I dont know how to fine my Primary DNS and my Default router.
    P.S.(I have a Mac OS X)

    Reply
  25. dfcsdcf says:
    February 18, 2007 at 5:40 am

    i need internet on my psp! but it dnt work because the IP address is timed out how do i untime it out

    Reply
  26. erika says:
    November 10, 2006 at 1:55 am

    Or just use this supremely easy URL:
    http://www.whatismyip.com/

    Reply
  27. John Bales says:
    April 16, 2005 at 6:42 am

    Assuming you have a single ethernet interface and an airport interface. Using Terminal.app you can use ipconfig.
    If you’re connected via ethernet:
    $ ipconfig getifaddr en0
    If you’re connect via airport:
    $ ipconfig getifaddr en1

    Reply
  28. Michael Clark says:
    April 13, 2005 at 1:59 am

    Three other ways to get your IP Address on OS X:
    1. Run the Network Utility (under Applications | Utilities ). Your IP address is in the Info tab, on the left, next to IP Address(es). You may need to change the “Network Interface”
    2. Open up “Network Preferences” on the Location menu (under the Apple). Your IP Address will be in the List of different connections.
    3. Use the “Net monitor” utility available from http://homepage.mac.com/rominar/net.html . It can be set to put a graph in your menu bar. Move your mouse over the graph and it will show a window with your IP Address.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Recent Posts

  • Important Google Chrome Ad Privacy Updates and Settings
  • How to Copy Photos from a Digital Camera to a Mac System
  • How to Play Sudoku on an Ubuntu Linux Computer
  • How to Connect to Xfinitywifi Internet from Windows 10
  • Step-by-Step: How to Add a Second User Account to a Chromebook

On Our YouTube Channel

ZEERA MagSafe iPhone Kickstand Case -- REVIEW

XGIMI Horizon Ultra 4K Video Projector -- REVIEW

Categories

  • AdSense, AdWords, and PPC Help (106)
  • Alexa, Kindle, and Nook Help (103)
  • Amazon, eBay, and Online Shopping Help (166)
  • Android Help (241)
  • Apple iPad Help (151)
  • Apple Watch & Smartwatch Help (56)
  • Articles, Tutorials, and Reviews (347)
  • Auto Tech Help (21)
  • Business Advice (201)
  • Chromebook & ChromeOS Help (48)
  • Computer & Internet Basics (797)
  • d) None of the Above (166)
  • Facebook Help (386)
  • Google, Chrome & Gmail Help (199)
  • HTML & Web Page Design (248)
  • Instagram & Threads Help (53)
  • iPhone & iOS Help (643)
  • iPod & MP3 Player Help (173)
  • LinkedIn Help (90)
  • Linux Help (179)
  • Linux Shell Script Programming (90)
  • Mac & MacOS Help (935)
  • Most Popular (16)
  • Outlook & Office 365 Help (41)
  • PayPal Help (68)
  • Pinterest Help (54)
  • Reddit Help (21)
  • SEO & Marketing (82)
  • Spam, Scams & Security (102)
  • Trade Show News & Updates (23)
  • Twitter Help (225)
  • Video Game Tips (66)
  • Web Site Traffic Tips (62)
  • Windows PC Help (981)
  • Wordpress Help (206)
  • Writing and Publishing (72)
  • YouTube Help (47)
  • YouTube Video Reviews (159)
  • Zoom, Skype & Video Chat Help (66)

Archives

Social Connections:

Ask Dave Taylor


Follow Me on Pinterest
Follow me on Twitter
Follow me on LinkedIn
Follow me on Instagram


AskDaveTaylor on Facebook



microsoft insider mvp


This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this site or on any linked site. Further, please note that by submitting a question or comment you're agreeing to our terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site. Our lawyer says "Thanks for your cooperation."
© 2023 by Dave Taylor. "Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.
Privacy Policy - Terms and Conditions - Accessibility Policy
x
x