0
I’m making a script that needs the machine IP on the network, tried several ways unsuccessfully until I figured out a way:
ip="`ip addr show | grep global | grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])' | sed -n '1p'`"
echo $ip
It worked, but it seems to me a very dirty method. Is there any other way to do it?
I would take it with ifconfig, but Debian 9 no longer comes with ifconfig by default and I didn’t know that hostname showed IP, thank you very much. !
– Everton
@Everton: Have you looked at
/sbin/ifconfig
?– Lacobus
The net-tools package, (which includes Arp, ifconfig, iptunnel, netstat, route, iwconfig, and nameif) was marked as obsolete by the linux foundation and therefore no longer used. https://wiki.linuxfoundation.org/networking/net-tools
– Everton
In Debian 9 the good old
ifconfig
has become obsolete, now the command is usedip -stats -color -human addr
– gfleck