What command do I want to issue when I want to know the IP address of the Solaris machine I'm logged onto?
-
3Feel like this question shouldn't be closed if it has gotten `22 upvotes` and `140,000 + views`... It is clearly a useful question to people – Kellen Stuart Apr 24 '18 at 21:02
-
@KellenStuart SO's primary directive is Maintaining Order - "useful" is a secondary concern – Conrad Mar 21 '23 at 20:49
8 Answers
If you're a normal user (i.e., not 'root') ifconfig
isn't in your path, but it's the command you want.
More specifically: /usr/sbin/ifconfig -a

- 11,894
- 12
- 69
- 85
-
1Of course, there may be many interfaces on the box, each with its own IP. – chris Mar 31 '09 at 18:57
-
Sure. You'll generally have at least two -- the local loopback (lo0) and one or more ethernet connections (on my machine, ce0). – Andrew Mar 31 '09 at 23:38
-
`-a` Apply the command to all interfaces of the specified address family. If no address family is supplied, either on the command line or by means of /etc/default/inet_type, then all address families will be selected. http://docs.oracle.com/cd/E19253-01/816-5166/6mbb1kq31/ – Ivan Chau Apr 18 '17 at 06:33
The following worked pretty well for me:
ping -s my_host_name

- 12,708
- 2
- 36
- 40

- 8,448
- 21
- 89
- 148
/usr/sbin/ifconfig -a | awk 'BEGIN { count=0; } { if ( $1 ~ /inet/ ) { count++; if( count==2 ) { print $2; } } }'
This will list down the exact ip address for the machine

- 107
- 1
- 1
The following shell script gives a nice tabular result of interfaces and IP addresses (excluding the loopback interface) It has been tested on a Solaris box
/usr/sbin/ifconfig -a | awk '/flags/ {printf $1" "} /inet/ {print $2}' | grep -v lo
ce0: 10.106.106.108
ce0:1: 10.106.106.23
ce0:2: 10.106.106.96
ce1: 10.106.106.109

- 3,327
- 6
- 30
- 47

- 51
- 1
- 1
Try using ifconfig -a
. Look for "inet xxx.xxx.xxx.xxx", that is your IP address

- 7,775
- 7
- 59
- 82

- 45,915
- 17
- 113
- 134
There's also:
getent $HOSTNAME
or possibly:
getent `uname -n`
On Solaris 11 the ifconfig command is considered legacy and is being replaced by ipadm
ipadm show-addr
will show the IP addresses on the system for Solaris 11 and later.

- 39
- 1
-
1The *getent* command takes a database as an argument. Perhaps you meant `getent hosts $HOSTNAME` or `getent hosts \`uname -n\`` – Scott Centoni Sep 11 '14 at 15:46
/usr/sbin/host `hostname`
should do the trick. Bear in mind that it's a pretty common configuration for a solaris box to have several IP addresses, though, in which case
/usr/sbin/ifconfig -a inet | awk '/inet/ {print $2}'
will list them all

- 670
- 3
- 6