解决方案
/sbin/ifconfig命令的默认输出所有接口的信息:
$ /sbin/ifconfig
输出示例:
ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.56.130 netmask 255.255.255.0 broadcast 192.168.56.255
inet6 fe80::282:cf47:597c:5c64 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:ab:5d:8a txqueuelen 1000 (Ethernet)
RX packets 28208 bytes 1781324 (1.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 2023 bytes 241140 (235.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 78 bytes 13542 (13.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 78 bytes 13542 (13.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
只查看ens32接口的IP信息
$ /sbin/ifconfig ens32
如果只想要IP信息,使用grep获取:
$ /sbin/ifconfig ens32| grep 'inet '
然后使用cut命令获取IP地址:
$ /sbin/ifconfig ens32| grep 'inet ' | cut -f 10 -d " "
或者使用awk 获取IP地址
/sbin/ifconfig ens32| grep 'inet ' | awk '{ print }'
如何获取分配给Linux接口ens32 的IP地址?
如何只获取某个接口的IP地址?
在shell中,如何只抓取网口的IP地址?
日期:2020-03-23 08:03:51 来源:oir作者:oir
