CentOS 通过shell脚本过滤得到服务器IP地址

1.CentOS 6.x (32Bit &&64Bit)

[root@localhost ~]# ifconfig |grep Bcast |awk '{print$2}' |sed 's/addr://g'
192.168.31.46

2.CentOS 7.x (32Bit &&64Bit)

[root@jenkins ~]# ip addr show ens33 |grep -w inet |awk '{print $2}' |awk -F '/' '{print $1}'
192.168.31.43
或者
[root@jenkins ~]# ip a show dev ens33|grep -w inet|awk '{print $2}'|sed 's//.*//'
192.168.31.43
原文地址:https://www.cnblogs.com/caoshousong/p/11383691.html