How do I find my local IP on a Mac?

With Windows boxes, I type “ipconfig” to figure out what my local IP address is (in the form of 192.168.1.xxx). What would I do on a Mac or through the terminal (Unix)?

In the terminal, type ifconfig. The first Ethernet device is called en0 and it’s probably the one you want.

Open up your networking control panel. It’ll be right there. Or in terminal use ifconfig with no parameters.

Thanks much for both solutions!

And realize that the concept of “my IP address” is pretty dated at this point. It’s very likely that you have multiples, even on a simple home machine. Parallels, for example, installs a “ghost” network adaptor with it’s own IP, Bluetooth may have one depending on how you’re set up, and of course there are the simple cases of having more than one network adaptor enabled.

I needed to know it for setting up port forwarding. It’s still applicable there, right?

Yes, you just need to get (a/the) right one for whatever purpose you’re using. In your case, one of the ones associated with the primary network adaptor.

But if your machines are set up to get addresses dynamically, your port forwarding will only work for as long as the machines have the same address (which may change at shutdown and other times). If you want (extended time) port forwarding, you probably want to give your computers static addresses – in which case it’s easy to look up the IP address in the control panel where you set it, rather than going to the command line.

This is probably more than you need, and if so, just disregard it. But recently I needed to write an AppleScript that would pop up a message with their IP address without them even having to know what System Preferences are.

In any case, I found that running the command “ipconfig getifaddr en0” was the easiest to handle–it simply returns the IP address for the default ethernet device, without all the other confusing things to sift through. It sure made it easier to write a quick AppleScript–no parsing necessary.

“Default internet device” may be somewhat confusing. en0 is the built-in Ethernet. If your machine has multiple built-in Ethernet ports, then they will be numbered en1 and so on. The AirPort card, if present, is numbered after the built-in Ethernet devices. Since most Macs have one Ethernet port and AirPort capability, en0 will be the Ethernet device and en1 will be the AirPort card. You may see a fw0, that’s for networking over FireWire; lo0, that’s the loopback interface; and gif0 and stf0, used for IPv6 tunneling. If a dial-up link is active, there will be a ppp0 interface.

If you look at the network control panel, it will tell you which via device you are connected to the internet, if in fact your are. Not sure how to glom that programatically, though.