获取多网卡下非回环地址的IP地址

回复 收藏
怎样获取多网卡下非回环地址的IP地址?

比如输入 ip a
只会出现eth0网卡信息 不会出现lo网卡信息
2015-08-17 15:20 举报
已邀请:
0

gjc159357

赞同来自:

太纠结   这个有必要么   你要么就正则  过滤网卡信息好了
0

346115392

赞同来自:

gjc159357 发表于 2015-8-17 15:46
太纠结   这个有必要么   你要么就正则  过滤网卡信息好了

ip a|grep -v  "lo|loopback|127.0.0.1"   这样怎样
0

gjc159357

赞同来自:

346115392 发表于 2015-8-17 15:52
ip a|grep -v  "lo|loopback|127.0.0.1"   这样怎样

你可以  ifconfig -a | grep "eth*"
0

346115392

赞同来自:

gjc159357 发表于 2015-8-17 15:55
你可以  ifconfig -a | grep "eth*"

这个不行呀  会把lo的加在后面  ip a 的时候也不能用
[root@localhost ~]# ip a | grep "eth*"
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
2: eth0: mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
    link/ether 00:0c:29:e1:c2:5f brd ff:ff:ff:ff:ff:ff
    inet 192.168.137.2/24 brd 192.168.137.255 scope global eth0
    inet6 fe80::20c:29ff:fee1:c25f/64 scope link
[root@localhost ~]# ifconfig |grep "eth*"
eth0      Link encap:Ethernet  HWaddr 00:0C:29:E1:C2:5F  
          inet addr:192.168.137.2  Bcast:192.168.137.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fee1:c25f/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:194 errors:0 dropped:0 overruns:0 frame:0
          TX packets:141 errors:0 dropped:0 overruns:0 carrier:0
          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:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
[root@localhost ~]#
0

loveyouhyf

赞同来自:

试试这个
ip a |grep "^.*eth"

ifconfig |grep "eth*"|sed -n '1,2p'

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: