如何过滤出主机IP地址?
解题思路
- 要想过滤出主机IP地址,首先必须得查看IP地址,而后过滤;
- 使用cut和grep命令;
1.查看主机IP地址
[root@localhost ~]# ip a
2.grep命令过滤
[root@localhost ~]# ip a | grep inet
3.ens关键字过滤
[root@localhost ~]# ip a | grep inet | grep ens
inet 192.168.253.128/24 brd 192.168.253.255 scope global dynamic noprefixroute ens160
4.cut命令继续过滤
[root@localhost ~]# ip a | grep inet | grep ens | cut -d / -f 1
inet 192.168.253.128
[root@localhost ~]# ip a | grep inet | grep ens | cut -d / -f 1 | cut -d " " -f 6
192.168.253.128
[root@localhost ~]#