-1

ifconfig shows too much information. I need to know all net interfaces no matter whether they are available or not and pair them with their ip addresses and masks.

In case if ficonfig returns

enp9s0    Link encap:Ethernet  HWaddr 54:be:f7:5c:99:0d  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
          Interrupt:18 

lo        Link encap:Локальная петля (Loopback)  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:256 errors:0 dropped:0 overruns:0 frame:0
          TX packets:256 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:19992 (19.9 KB)  TX bytes:19992 (19.9 KB)

wlp8s0    Link encap:Ethernet  HWaddr f8:2f:a8:f3:1b:31  
          inet addr:192.168.0.102  Bcast:192.168.0.255 Mask:255.255.255.0
          inet6 addr: fe80::820d:4dd0:b3f9:10ed/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:241 errors:0 dropped:0 overruns:0 frame:4220
          TX packets:301 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:101434 (101.4 KB)  TX bytes:101132 (101.1 KB)
          Interrupt:17

Example output:

    enp9s0: addr:- Mask:-
    lo: addr:127.0.0.1 Mask:255.0.0.0
    wlp8s0: addr:192.168.0.102 Mask:255.255.255.0
  • 1
    Welcome to SO, it is advisable on SO to add your effort too which you have put in order to solve this problem(use code tags for samples). – RavinderSingh13 Nov 03 '18 at 12:35

2 Answers2

1
ifconfig | awk '/^[^ ]/{i=$1; getline; if($1=="inet") {print i": "$2,$NF} else {print i": addr:- Mask:-"}}'

Output:

enp9s0: addr:- Mask:-
lo: addr:127.0.0.1 Mask:255.0.0.0
wlp8s0: addr:192.168.0.102 Mask:255.255.255.0

Btw: With Ubuntu, ifconfig is deprecated and replaced by iproute2.

Cyrus
  • 84,225
  • 14
  • 89
  • 153
0
only ip:
ip a|grep -v inet6|grep inet|awk '{print $2}'|sed -e 's/\// /g' |awk '{print $1}'
ip with mask:
ip a|grep -v inet6|grep inet|awk '{print $2}'