10

Is there a Linux command that visualizes configured network interfaces in a tree view, just like lsblk does for block devices?

The output of such a program could for example look like this (bottom-up-approach):

eth0   
└─bond0
  ├─bond0.42
  │ └─br42
  └─bond0.43
    └─br43
eth1
└─bond0
  ├─bond0.42
  │ └─br42
  └─bond0.43
    └─br43
tap100i0
└─br42
tap100i1
└─br43
tap101i0
└─br42
tap101i1
└─br43

or this (top-down-approach):

br42
├─bond0.42
│ └─bond0
│   ├─eth0
│   └─eth1
├─tap100i0
└─tap101i0
br43
├─bond0.43
│ └─bond0
│   ├─eth0
│   └─eth1
├─tap100i1
└─tap101i1

Note: I am not looking for a tool that produces this exact output, but rather asking if anyone knows a command with a similar result.

2
  • did you try ip addr ??
    – Sidahmed
    Dec 31, 2016 at 17:58
  • yes, but ip addr returns a flat list of network interfaces, not a hierarchical tree view
    – jlauinger
    Jan 2, 2017 at 16:03

2 Answers 2

6

I have search for an option in existing utilities but I have not found any. Nevertheless the desired functionality is useful from my point of view. So I did a simple bash script that parses ip link show command and prints something similar to the desired output in the question:

$ ./nettree.sh -u
eth3
    bond1
       bond0
eth2
    bond0
eth1
    bond0
eth0
lupen3
    bond1
       bond0
lo
lxcbr0
virbr0
veth6404e35
    docker0

I pushed the script to github: https://github.com/zabojcampula/show-net-devices-tree

1
  • I forked your script, and ended up reimplementing the main logic differently. See my answer to this thread. Thanks! Jul 1, 2023 at 14:42
2

I found the pre-existing Accepted Answer to this Q, and used it for years myself.

Recently I found myself updating/tweaking it a bit to detect VLAN device hierarchies, PPPoE, and other things. Then basically completely rewrote it.

In contrast to the AA the files/folders under /sys/class/net/ and /proc/net/ are examinded to build the hierarchy.

Output formats are tree, utf, and graphviz. It also also querying remote ssh-hosts with the -s option:

$ ./nettree.sh 
meshif
└── bat0
    └── vswitch
        ├── hmv
        │   └── home
        └── iso
wlp2s0

$ ./nettree.sh -d -l
wlp2s0
home ━┓
      ┗━ hmv ━┓
              ┗━ vswitch ━┓
                          ┗━ bat0 ━┓
                                   ┗━ meshif
iso ━┓
     ┗━ vswitch ━┓
                 ┗━ bat0 ━┓
                          ┗━ meshif

$ ./nettree.sh -d -G
graph iftree {
  "wlp2s0"[label="wlp1s0", class="wireless"];
  "switch"[label="switch", class="switch"];
  "hmv"[label="homev", class="virtual"];
  "bat0"[label="bat0", class="virtual"];
  "home"[label="home", class="bond"];
  "iso"[label="iso", class="virtual"];
  "meshif"[label="usbxg2a", class="wireless"];
  "home" -- "hmv"[label=""];
  "hmv" -- "vswitch"[label=""];
  "iso" -- "vswitch"[label=""];
  "vswitch" -- "bat0"[label=""];
  "bat0" -- "meshif"[label=""];
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .