Mason Mason - 1 year ago 75
Bash Question

Which terminal command to get just IP address and nothing else?

I'm trying to use just the IP address (inet) as a parameter in a script I wrote.

Is there an easy way in a unix terminal to get just the IP address, rather than looking through


Answer Source

You can write a script that only return the IP like:

/sbin/ifconfig eth0 | grep 'inet addr' | cut -d: -f2 | awk '{print $1}'

For MAC:

ifconfig | grep "inet " | grep -v | cut -d\  -f2

Or for linux system

hostname -i | awk '{print $3}' # Ubuntu 

hostname -i # Debian
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download