Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...