Visit Our UNIX and Linux User Community


Ip


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Ip
# 1  
Old 02-08-2007
Ip

Mates,

Is there a command to get the ipaddress only of my system. ie; like hostname where i get my hostname i need the output dispay only my ipaddress. I am using a linux server.

thanks
# 2  
Old 02-08-2007
Hey,

the only way - take your hostname and scan /etc/hosts for the
associated ip-number.

CU
lowbyte
# 3  
Old 02-08-2007
yeah thats one way i got it..

cat /etc/hosts|grep `hostname`|awk '{print$1}'

also then the using ping -c1 `hostname` and taking only ipaddress

is there any other way.
# 4  
Old 02-08-2007
This is an error prone way of doing things, there could be multiple lines that match, or the hostname could be in a commented line.

Getent is more reliable, and safe.

One way:

Code:
set -- $(getent hosts $(hostname))
ipaddress=$1

# 5  
Old 02-08-2007
I would say use the "ifconfig" command.

Allthough it's not common for Unix systems, but a system could get it's IP from a DHCP server. There are even other options where the systems IP is not necessary in the /etc/hosts file.

So, consulting the host file is no guarantee for success.
# 6  
Old 02-09-2007
Thanks for your suggestion mates
 

Previous Thread | Next Thread
Test Your Knowledge in Computers #479
Difficulty: Medium
A address usually refers to a single byte of memory (called bitwise-addressing).
True or False?

Featured Tech Videos