0

I use ip a to get the IP address of my machine. Sometimes, it is getting difficult to identify when I have 20+ network interfaces.

Is there a way to display only network interfaces which has IP? The network interface which don't have the IP address should be ignored and should not be displayed.

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
   valid_lft forever preferred_lft forever
inet6 ::1/128 scope host 
   valid_lft forever preferred_lft forever
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 4c:cc:6a:32:42:0b brd ff:ff:ff:ff:ff:ff
inet 10.76.99.232/23 brd 10.76.99.255 scope global noprefixroute dynamic eno1
   valid_lft 81438sec preferred_lft 81438sec
inet6 fe80::4cd3:b92f:e2:54c8/64 scope link noprefixroute 
   valid_lft forever preferred_lft forever
3: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 52:54:00:67:f0:89 brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
   valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:67:f0:89 brd ff:ff:ff:ff:ff:ff   
5: virbr1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:8e:77:61 brd ff:ff:ff:ff:ff:ff
inet 192.168.100.1/24 brd 192.168.100.255 scope global virbr1
   valid_lft forever preferred_lft forever
6: virbr1-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr1 state DOWN group default qlen 1000
link/ether 52:54:00:8e:77:61 brd ff:ff:ff:ff:ff:ff
7: br-251ee4bbddbc: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
link/ether 02:42:59:14:5d:96 brd ff:ff:ff:ff:ff:ff
inet 172.20.0.1/16 brd 172.20.255.255 scope global br-251ee4bbddbc
   valid_lft forever preferred_lft forever
inet6 fe80::42:59ff:fe14:5d96/64 scope link 
   valid_lft forever preferred_lft forever
8: br-7d1010889446: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
link/ether 02:42:e9:35:47:a7 brd ff:ff:ff:ff:ff:ff
inet 172.19.0.1/16 brd 172.19.255.255 scope global br-7d1010889446
   valid_lft forever preferred_lft forever
9: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
link/ether 02:42:a2:bf:15:a8 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0
   valid_lft forever preferred_lft forever
inet6 fe80::42:a2ff:febf:15a8/64 scope link 
   valid_lft forever preferred_lft forever
11: veth42032d5@if10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-251ee4bbddbc state UP group default 
link/ether 56:1f:89:31:03:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet6 fe80::541f:89ff:fe31:302/64 scope link 
   valid_lft forever preferred_lft forever 
13: veth6b578c7@if12: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master docker0 state UP group default 
link/ether da:12:96:51:48:48 brd ff:ff:ff:ff:ff:ff link-netnsid 1
inet6 fe80::d812:96ff:fe51:4848/64 scope link 
   valid_lft forever preferred_lft forever
15: veth36b9b3b@if14: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br-251ee4bbddbc state UP group default 
link/ether 9e:89:cb:57:36:67 brd ff:ff:ff:ff:ff:ff link-netnsid 2
inet6 fe80::9c89:cbff:fe57:3667/64 scope link 
   valid_lft forever preferred_lft forever
34: br-22ddff6ae6ef: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default 
link/ether 02:42:d7:77:d5:2d brd ff:ff:ff:ff:ff:ff
inet 172.18.0.1/16 brd 172.18.255.255 scope global br-22ddff6ae6ef
   valid_lft forever preferred_lft forever

Expected output (approx):

1. eno1: 10.76.99.232 
3. virbr0: 192.168.122.1
5. virbr1: 192.168.100.1 

etc.

I'm looking for any native way of filtering using ip tool. Using other tools to get the expected output is also appreciated.

1
ip -4 -brief address show

will display minimal address informations, incidentally showing only the interfaces with IPv4 addresses, since told to display only IPv4 (ie: not ethernet nor IPv6 addresses).

This option was added lately (2015) to the iproute2 utilities and took time to move to distributions. For example, it's:

  • available in Debian 9 but not Debian 8
  • available in RHEL 7.5 but not some previous RHEL 7 releases.

The upstream commit:

add support for brief output for link and addresses

The output would probably start with:

$ ip -4 -brief address show
lo               UNKNOWN        127.0.0.1/8 
eno1             UP             10.76.99.232/23
virbr0           UP             192.168.122.1/24 
virbr1           UP             192.168.100.1/24 

...

1
  • thanks a lot for the information, it's very helpful. – smc Sep 10 '18 at 19:38
3
ip -o addr show  

would be an option. It shows each IP address on one line, with multiple lines for interfaces with more than one IP address and no line for interfaces without an address.

Read man ip.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.