最簡答的方法
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]#