[root@archsitdb203 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet 10.27.139.185/32 scope global lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether fa:16:3e:fd:41:4a brd ff:ff:ff:ff:ff:ff
inet 10.27.139.187/27 brd 10.27.139.191 scope global eth0
inet 10.27.139.184/32 scope global eth0
inet6 fe80::f816:3eff:fefd:414a/64 scope link
valid_lft forever preferred_lft forever
[root@archsitdb203 ~]# ip add show eth0 | grep "scope global" |grep "brd" | awk '{ print $2}'|cut -d "/" -f1
10.27.139.187
[root@archsitdb203 ~]# ifconfig
eth0 Link encap:Ethernet HWaddr FA:16:3E:FD:41:4A
inet addr:10.27.139.187 Bcast:10.27.139.191 Mask:255.255.255.224
inet6 addr: fe80::f816:3eff:fefd:414a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:449473649 errors:0 dropped:0 overruns:0 frame:0
TX packets:716237658 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:66727718736 (62.1 GiB) TX bytes:106335603852 (99.0 GiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:209168451 errors:0 dropped:0 overruns:0 frame:0
TX packets:209168451 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:50858540919 (47.3 GiB) TX bytes:50858540919 (47.3 GiB)
[root@archsitdb203 ~]# ifconfig eth0 | grep "inet addr" | awk '{ print $2}' | awk -F: '{print $2}'
10.27.139.187
原文:https://www.cnblogs.com/Coye/p/10873791.html