86

How do I remove a bridge that has an IP address that was brought up manually and isn't in /etc/network/interfaces?

$ ifconfig br100                                                
    br100     Link encap:Ethernet  HWaddr 00:00:00:00:00:00                         
              inet addr:172.16.0.5  Bcast:172.16.0.255  Mask:255.255.255.0

Can't delete it:

# brctl delbr br100
bridge br100 is still up; can't delete it   

Can't bring it down with ifdown:

# ifdown br100                                                  
ifdown: interface br100 not configured     
Lorin Hochstein
  • 8,077
  • 17
  • 50
  • 56

7 Answers7

120

Figured it out:

# ip link set br100 down
# brctl delbr br100
Lorin Hochstein
  • 8,077
  • 17
  • 50
  • 56
  • 1
    To delete all bridge interfaces do `sudo ip link show | grep br- | awk -F ':' '{print $2}' | tr -d ' ' | while read b; do sudo ip link set "$b" down; sudo brctl delbr "$b"; done` – sebastian Nov 16 '19 at 10:12
  • I stumbled upon an info that "brctl" is obsolete as of centos8 (and may be missing from the repos). Use "ip" as in answer by robo – Patryk Mazurkiewicz Feb 09 '22 at 10:49
  • this might be useful, command to get the interface based on the ip `ifconfig | grep 172.16` – Aditya Kresna Permana Jun 29 '22 at 09:14
34
$ sudo ip link delete br0 type bridge

that's all

robo
  • 341
  • 3
  • 2
16

To clarify this for future.

ifup and ifdown are commands from some flavours of linux. And are used to control network settings set in /etc/network/interfaces for debian based systems and /etc/sysconfig/network-scripts/ifcg* on Redhat based systems (I cannot comment on others).

Creating and removing interfaces manually is done by using ifconfig (or ip which is bit more tricky to use). Bridges can be controlled with brctl

So after removing all interfaces from a bridge with brctl delif <bridg> <if> it can be moved to "down state" with ifconfig br100 down (or ip link set br100 down) and can now be removed with brctl delbr br100

Please note that using network-manager to manage your networks might make your manually changed interfaces to reset.

Manwe
  • 406
  • 2
  • 8
  • There seems to be some division of labour between `brctl` and `ip/ifconfig` (as illustrated by the accepted answer above at https://unix.stackexchange.com/a/31765/262897) but also some overlap in functionality (as illustrated by e.g. https://unix.stackexchange.com/a/324535/262897). So to say "Bridges can be controlled with `brctl`" seems to be only part of the story. Is there a simple way to summarize the relationship between the two/three? – Christoph Mar 07 '20 at 12:38
  • 1
    `brctl` controls the bridge-device. E.g it binds the real network devices together to create a bridge-network device. The then created bridge-device is almost like any other network device and you control it with `ip/ifconfig` commands. To remove real-interfaces or the bridge, one has to first bring down the interface with `ip/ifconfig`. In short, `brctl` controls bridge creation and interface bindings. `ip/ifconfig` control network interface (bridge device is also network interface) state and addresses. – Manwe Mar 10 '20 at 13:48
14

How about?

docker network prune
Czollli
  • 141
  • 1
  • 3
9

On macOS and possibly some BSD systems:

sudo ifconfig [bridge-name] down
sudo ifconfig [bridge-name] destroy
rien333
  • 613
  • 4
  • 15
2

First you need to delete all the interfaces linked to your bridge using this command

ovs-vsctl del-port br-ex INTERFACE_NAME

Then you can delete the bridge

ovs-vsctl del-br br-ex
Romeo Ninov
  • 16,541
  • 5
  • 32
  • 44
NIna
  • 29
  • 4
1

Also run:

virsh net-list --all  
sudo virsh net-list --all   
sudo virsh net-destroy default  
sudo virsh net-undefine default  
[...]  
sudo nmcli connection show
sudo nmcli connection delete br0
[...]  

before using the command in robo's answer if you're using GNU/Linux.

mYnDstrEAm
  • 4,008
  • 13
  • 49
  • 108