1

I am trying to write a bash script to configure an app (unattended install). All I need to do is this. I need to get the IP address for the server and set it as a variable. I am writing this script to simplify that. What I have noticed is that when I test this in a vps though eth0 is listed its not the default, its something along the lines of venet0:0. Is there any way of getting this ip set as a vaiable (I know how to if I know the interface name, i am trying to do this without knowing as its hard to plan for every possible device naming). if not then i will just add a prompt for the ip address for the user right as they run the script.

This is not a duplicate question as I am asking for the server's IP not just the public IP of the server. Even though this is aimed at building a public mail server I am building it to work on an internal one as well.

2 Answers2

2

'The' IP address... servers have so many, default management, application, DB listener?

Does this do it for you?

IP_ADDR=$(getent hosts `hostname` | awk '{print $1}')
Sirch
  • 5,697
  • 4
  • 19
  • 36
0

If you have one interface:

ip addr show | grep "inet " | grep -v "127.0.0.1/8" | awk '{print $2}'
10.10.1.254/16
Danila Ladner
  • 5,241
  • 21
  • 30