三剑客取ip地址
2019-10-12 本文已影响0人
linux_龍
image.png
image.png
[root@m01 ~]# hostname -I|awk '{print $1}'
10.0.0.61
[root@m01 ~]# hostname -I|cut -d " " -f1
10.0.0.61
[root@m01 ~]# awk -F= '/IPADDR/{print $2}' /etc/sysconfig/network-scripts/ifcfg-eth0
10.0.0.61
[root@m01 ~]# sed -n '/IPADDR/s#^.*=##gp' /etc/sysconfig/network-scripts/ifcfg-eth0
10.0.0.61
[root@m01 ~]# ip a s eth0 |awk -F'[ /]+' 'NR==3{print $3}'
10.0.0.61
[root@m01 ~]# ip a s eth0 |awk -F'inet |/24' 'NR==3{print $2}'
10.0.0.61
[root@m01 ~]# ip a s eth0 |awk -F'[^0-9.]+' 'NR==3{print $2}'
10.0.0.61
[root@m01 ~]# ip a s eth0 |sed -nr '3s#^.*et |/.*$##gp'
10.0.0.61
[root@m01 ~]# ip a s eth0 |sed -nr '3s#^.*et (.*)/.*$#\1#gp'
10.0.0.61