shell命令-獲取主機IP

[root@rhel8 mnt]# ifconfig ens160 
ens160: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.10  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::20c:29ff:fe94:a86  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:94:0a:86  txqueuelen 1000  (Ethernet)
        RX packets 2714  bytes 615269 (600.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 417  bytes 37838 (36.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
[root@rhel8 mnt]# ifconfig ens160 | grep "inet " | cut -d " " -f 10
192.168.1.10
[root@rhel8 mnt]# ifconfig ens160 | grep "inet " | awk '{print $2}'
192.168.1.10
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章