Find all Ethernet interface and associate IP address

6,134

Solution 1

I think i found something, i am sure there must be more smart way but for now i am all set.

[root@server1 ~]# ip -o -4 addr show | awk '{print $1" " $2": "$4}'
1: lo: 127.0.0.1/8
2: eno1: 192.168.100.190/24
3: eno2: 10.5.8.33/21

Solution 2

This command displays the all the interfaces and their respective ip adress separated by a space in a line

ip r|grep " src "|cut -d " " -f 3,12 | xargs

reference: https://stackoverflow.com/questions/38041163/display-only-network-interface-and-ip-address-using-ifconfig-and-awk

Solution 3

Try this:

ip addr show | awk -F '[: ]+' '
    /^[^ ]/      { iface=$2 }               # Start of section, we memorize the interface name
    $2 == "inet" { print iface ": " $3 }    # IPv4 address => print the line
'

Solution 4

There is an example:

ip address show | awk '/inet / {split($2,var,"/*"); print $7,":",var[1]}'

the output should be somthing like:

 : 127.0.0.1
enp3s0f0: 10.5.2.10
enp3s0f1: .......
enp4s0f0: .......
enp4s0f1: .......

Solution 5

This gives a report in the format you requested:

# ip -o -4 addr show | awk '{print $2": "$4}'
Share:
6,134
Satish
Author by

Satish

Curious about everything.

Updated on September 18, 2022

Comments

  • Satish
    Satish almost 2 years

    How do I get all interface and associate IP address like following

    [root@centso ]# ifconfig
    enp3s0f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet addr:10.5.2.10  Bcast:10.5.7.255  Mask:255.255.248.0
            inet6 fe80::e611:5bff:feea:5e50  prefixlen 64  scopeid 0x20<link>
            ether e4:11:5b:ea:5e:50  txqueuelen 1000  (Ethernet)
            RX packets 638000416  bytes 763371981799 (710.9 GiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 16607280  bytes 9787019600 (9.1 GiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    enp3s0f1: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
            ether e4:11:5b:ea:5e:52  txqueuelen 1000  (Ethernet)
            RX packets 0  bytes 0 (0.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 (0.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    enp4s0f0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
            ether e4:11:5b:ea:5e:44  txqueuelen 1000  (Ethernet)
            RX packets 0  bytes 0 (0.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 (0.0 B)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    enp4s0f1: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
            ether e4:11:5b:ea:5e:46  txqueuelen 1000  (Ethernet)
            RX packets 0  bytes 0 (0.0 B)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 0  bytes 0 (0.0 B)
            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 1  (Local Loopback)
            RX packets 45015  bytes 4371658 (4.1 MiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 45015  bytes 4371658 (4.1 MiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    

    I want output like following, also I believe there is a command ip link or something does that but didn't recall, also some machine has nic name different like enoX or ethX

    enp3s0f0: 10.5.2.10
    enp3s0f1:
    enp4s0f0:
    enp4s0f1:
    
  • niglesias
    niglesias almost 7 years
    It's simpler and conforms to the requested report format. I've edited a previous answer but it seems it hasn't passed the review.