Linux Bash get IP address

Today I’ve tried to prepare auto configuration of my application and one of the main point was create correct cluster with real IP addresses . For example you have some config files where you want to put real IP of installed machine. In real Linux world it should be configured manually after installation but I want to emulate auto configuration, so, I’ve prepared bash script for auto config all parameters for my app, but one point was interesting and I’ve decided to describe it in a few words.

So, How to get real IP address ? Each of us know that there are ifconfig util and we can get all information about interfaces and addresses, I’ve used this for prepared short script to get real IP v4 address

ifconfig eth0  $1 | grep “inet addr” | awk -F: ‘{print $2}’ | awk ‘{print $1}’

Use it in your scripts if you want to do tasks as I had.

READ  Loops in Java

Leave a Reply

Your email address will not be published. Required fields are marked *