How to Get IP Address Linux

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 to get ip address on linux 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 IP address on Linux  ? 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.

Leave a Reply

Your email address will not be published.