LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   General (http://www.linuxquestions.org/questions/general-10/)
-   -   How to display only ipadress of system? (http://www.linuxquestions.org/questions/general-10/how-to-display-only-ipadress-of-system-4175451648/)

wwinay 02-25-2013 01:27 PM

How to display only ipadress of system?
 
Hello Linux Lovers, i have one trouble that how to display only ip address of systeme like 172.24.1.1 insted of displaying all ifconfig result...please help me out...

Thank You...

273 02-25-2013 01:43 PM

I was curious so I googled and found this:
Code:

hostname -i
However, for me that just gives 127.0.0.1, so I tried:
Code:

hostname -I
Which seems to do the job.
Edit: I should add that this can be run as a non-root user also, which is nice.

rtmistler 02-25-2013 01:44 PM

Depends if you need it via the shell or in a program.

One way would be: (for interface "eth0"

Quote:

ifconfig eth0 | grep "inet addr"
That still shows the broadcast address and subsystem mask.

You can post process that result to get only the IP address portion of that.

wwinay 02-25-2013 02:04 PM

Thank You
 
Yep,,,, hostname -I real works thaning you.....

venkatesh51 03-05-2013 07:20 AM

host hostname
 
inorder to display ip address only
we need to follow the steps
$hostname
$host (hostname)(hostname will come from the above command)
ex $host ravi

w1k0 03-08-2013 06:20 AM

Slackware 14.0:

hostname -I
Code:

hostname: invalid option -- 'I'
/sbin/ifconfig eth0 | grep "inet addr"
Code:


(Empty output.)

Explanations:

1. Your distribution uses some other hostname program version.

2. Modern ifconfig changed the format of the displayed data.

Solution:

/sbin/ifconfig eth0 | grep "inet" | awk '{print $2}'
Code:

192.168.1.2
deaf:abbe:bade:dead:beef:feed



All times are GMT -5. The time now is 08:57 AM.