Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I know you can do ifconfig | grep inet, but that shows you several IP addresses. How do I get the specific one for SSHing et al?

share|improve this question
add comment

5 Answers 5

up vote 6 down vote accepted

Use ipconfig getifaddr en1 for wireless, or ipconfig getifaddr en0 for ethernet.

share|improve this answer
add comment

You can do the following:

Type ifconfig or ifconfig -a. This command shows you the list of interfaces along with their IP and MAC addresses (the latter one only if applicable). You can also type ifconfig en0 or ifconfig en1 for the configuration of a particular interface only (as someone said in their answers, en0 is typically the wired Ethernet while en1 is the WiFi interface).

As an alternative, netstat -i will list all interfaces and will show you the IP addresses you have assigned to each of them.

Typically, when you have SSH daemon running on a box, it will listen on all available interfaces, ie. you can use any IP address that's configured on your machine to connect to that machine via SSH (this, obviously, subject to Firewall rules). If you're after what the OS calls a Primary interface and primary IP address, you can use the scutil command like this:

MacBook:~ scutil
> show State:/Network/Global/IPv4
<dictionary> {
  PrimaryInterface : en0
  PrimaryService : C0550F84-5C07-484F-8D62-C8B90DC977D8
  Router : 10.103.4.1
}
> show State:/Network/Interface/en0/IPv4
<dictionary> {
  Addresses : <array> {
    0 : 10.103.4.234
  }
  BroadcastAddresses : <array> {
    0 : 10.103.4.255
  }
  SubnetMasks : <array> {
    0 : 255.255.255.0
  }
}

Please note, that the above, even though is a command-line command, is also interactive (so you run scutil and then enter its own commands into it). The first show command tells you the name of the primary interface for the OS (i.e. this will be the one on top of the list in your System Preferences / Network Preferences window), as well as the IP address of your default router. The second show command takes State:/Network/Interface/<ifname>/IPv4 argument (in this case, en0) and gives you the IP addresses assigned to it. You're looking for the address in the Addresses array, the other two entries are broadcast addresses and the netmasks.

Hope that helps, but if anything is not clear, let me know.

share|improve this answer
add comment

In a terminal window, after the $ sign, do: curl ipecho.net/plain; echo

share|improve this answer
    
While you can get the WAN IP address with this command, you may need the LAN IP for SSH access depending on your setup. –  Scot Feb 14 at 6:20
add comment

You can use the following command to find ip address on Linux :

ip addr show

or

ip addr show eth0

Sample output : eth0: mtu 1500 qdisc mq state UP qlen 1000 link/ether b8:ac:6f:65:31:e5 brd ff:ff:ff:ff:ff:ff inet 192.168.2.100/24 brd 192.168.2.255 scope global eth0 inet6 fe80::baac:6fff:fe65:31e5/64 scope link valid_lft forever preferred_lft forever You can also check your ip using the site http://www.ip-details.com/ .

share|improve this answer
2  
Answers relating to Linux don't really help on an OS X site :-) –  patrix Apr 2 '13 at 9:14
add comment

everything works on the linux termianl. im not sure if Unix terminal will accept the ipconfig command. either do linux

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.