jeudi 18 janvier 2024

LInux/Debian : removing unnecessary network bridges

Lately, I've been fooling aroung a lot with containers  (docker) and virtual machines (Vagrant, VirtualBox, ...)
Lots of fun, but an unexpected consequence is that this created a lot of network bridges on my machine.

Thus, this output:

$ nmcli device status
DEVICE             TYPE      STATE         CONNECTION      
wlo1               wifi      connected     eduroam         
br-16841f4ab5b3    bridge    connected     br-16841f4ab5b3 
br-6d277fff70af    bridge    connected     br-6d277fff70af 
br-70abc1ec9d13    bridge    connected     br-70abc1ec9d13 
br-7866640acd2f    bridge    connected     br-7866640acd2f 
br-804db4145aa9    bridge    connected     br-804db4145aa9 
br-989ab8bd5062    bridge    connected     br-989ab8bd5062 
br-c393b3577508    bridge    connected     br-c393b3577508 
br-c4e437f7076a    bridge    connected     br-c4e437f7076a 
docker0            bridge    connected     docker0         
virbr0             bridge    connected     virbr0  

Those "br-" network interfaces are actually "bridges", used to connect an interface to another (see here for details).

Not really bad, but things are getting a bit crowded here, so I wanted to get rid of these at once. Here we go: 

 * To get only the names of the bridges:

$ nmcli device status | grep br- | awk -e '{print $1}'
br-16841f4ab5b3
br-6d277fff70af
br-70abc1ec9d13
br-7866640acd2f
br-804db4145aa9
br-989ab8bd5062
br-c393b3577508
br-c4e437f7076a
To remove them, the command is $ nmcli device delete <device>
So, as a oneliner:
$ for a in $(nmcli device status | grep br- | awk -e '{print $1}'); do nmcli device delete $a; done

Et voila ! 

 

Other related commands: