use*_*277 45 bash ip-address centos7
以前我在bash中使用以下命令来查找我的服务器的主ip
ipaddr=$(/sbin/ifconfig|grep inet|head -1|sed 's/\:/ /'|awk '{print $3}' | grep -v '127.0.0.1')
Run Code Online (Sandbox Code Playgroud)
但是在centos7中它不再有效,因为ifconfig不可用,即使我安装ifconfig使用命令也不再有效yum install net-tools
centos 7的等效命令是什么
非常感谢
Ale*_*der 86
您可以使用hostname命令:
ipaddr=$(hostname -I)
Run Code Online (Sandbox Code Playgroud)