I need to put the IP of my VPS machine into a variable. I mean to the external IP address appearing the value of inet addr
section, in ifconfig
output.
I've tried:
ipa="$(hostname -i)"
But echo ${ipa}
brought the localhost token: 127.0.1.1
, so I looked for other solutions and all I found includes many pipes and awk
operations which I know nothing about (never used awk
and I'm not very familiar with regex).
I tried this:
ipa=$(ifconfig | grep "inet addr:[0-999]\.[0-999]\.[0-999]\.[0-999]")
But it failed given that echo ${ipa}
has an empty line of output.
Why did what I've tried failed or at least how would you solve it?