Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Linux by (18.4k points)
I am trying to use the IP address (inet) as my parameter in the script I wrote.

Is there an easy way in a UNIX terminal to get just the IP address, rather than looking for ifconfig?

1 Answer

0 votes
by (36.8k points)

You need to 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 127.0.0.1 | cut -d\  -f2

Or for linux system

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

hostname -i # Debian

To know about Linux join the Linux training

If you are a beginner, do check out the video below:

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Nov 24, 2020 in Linux by blackindya (18.4k points)

Browse Categories

...