1

I'm using Linux CentOS 6.4 .

I'm writing a shell script and I need to extract a machine's IP in order to use it in the script. How can I find the machine's IP?

I'm looking for the "best" way because I know there are a few ways to get IP addresses.

Thanks

Itai Ganot
  • 10,976

2 Answers2

7

Here are ways to get your Linux machine IP address:

/sbin/ifconfig 

If you know the name of your Network Interface card, you can specify it in the command and get the results for that specific NIC:

/sbin/ifconfig eth0

Another command is:

/sbin/ip addr

If you know the name of your Network Interface card, you can specify it in the command and get the results for that specific NIC:

/sbin/ip addr show eth0

I think this is the best way:

hostname -i

Bare in mind that in some servers you might have more than one Network Interfacr Cards...

Itai Ganot
  • 10,976
0

I'd use facter for that.

yum install facter
facter ipaddress
facter ipaddress_eth0