Linux 一行命令 仅显示某一个网卡的ip地址

最简答的方法

1. 先使用 ifconfig 查看网卡的设备名

 2. 然后输入命令

ifconfig ens192 |grep 'inet ' |cut -d " " -f 10

命令解析
第一个 ens192 使用 ifconfig 进现实某一个网卡的信息
第二个 grep 后面inet 后面空格 可以进现实ipv4的ip地址.
第三行 cut -d " " 使用空格进行拆分, 貌似一个空格就算一个 所以到了ip地址 是10 想对应的子网掩码就是netmask是12了 掩码的值就是13

3.效果为

注意 去掉网卡设备名 就能够现实所有的ip地址了

[root@centos76 add]# ifconfig ens192  |grep 'inet ' |cut -d " " -f 10
10.24.22.234
[root@centos76 add]# ifconfig  |grep 'inet ' |cut -d " " -f 10
10.24.22.234
127.0.0.1
192.168.122.1
[root@centos76 add]# 

猜你喜欢

转载自www.cnblogs.com/jinanxiaolaohu/p/12131810.html