Industry guru Dave Taylor offers free tech support on a wide variety of technical and business topics, including HTML, Apple iPhone, online advertising, Cascading Style Sheets, Web design, management, Unix, Linux, search engine optimization, online dating, Mac OS X, shell script programming and Microsoft Windows.

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

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?


Dave's Answer:

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:

$ 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!



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Stumble Upon    

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments

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.

Posted by: Michael Clark at April 13, 2005 1:59 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

Posted by: John Bales at April 16, 2005 6:42 AM

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

Posted by: erika at November 10, 2006 1:55 AM

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

Posted by: dfcsdcf at February 18, 2007 5:40 AM

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)

Posted by: michael m. at March 12, 2007 6:02 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!!!

Posted by: Jasmine at January 28, 2009 5:43 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???

Posted by: Kimberley at March 3, 2009 9:00 PM

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

Posted by: madhu at July 23, 2009 1:09 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

Posted by: willa at July 24, 2009 10:28 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.

Posted by: Dave Taylor at July 26, 2009 12:08 AM

I have a lot to say, but ...
Starbucks coffee cup I have a lot to say, and questions of my own for that matter, but most of all I'd like to say thank you for all your efforts on this Web site by buying you a chai!

I do have a comment, now that you mention it!











Remember personal info?


Please note that I will never send you any unsolicited commercial email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









snow leopard pre order advert amazon

Follow me on Twitter @DaveTaylor

Search
Find just the answers you seek from among our 2300+ free tech support articles by using our Lijit search engine.


Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Book Links
© 2002 - 2009 by Dave Taylor. All Rights Reserved.

Note: 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 web site or on any linked site.

[whiteboard marker tray]
"Ask Dave Taylor®" is a registered trademark of Intuitive Systems, LLC.