Skip to content

Instantly share code, notes, and snippets.

@frjaraur
Created October 4, 2020 17:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save frjaraur/7bad30cedc484486efd3ba5d12362bec to your computer and use it in GitHub Desktop.
Save frjaraur/7bad30cedc484486efd3ba5d12362bec to your computer and use it in GitHub Desktop.
Libvirt-KVM create Bridge Interface using nmcli
### Show Active Interfaces
```
$ nmcli con show --active
```
### Create a Bridge Interface
```
$ nmcli con add ifname br0 type bridge con-name br0
Connection 'br0' (892869fe-f8ac-4f17-ace9-b8aeeeee61a0) successfully added.
```
### Link Bridge Interface to Real Interface (enp0s25 on this recipe)
```
$ nmcli con add type bridge-slave ifname enp0s25 master br0
Connection 'bridge-slave-enp0s25' (33ee8c62-48d8-4789-97df-604c479b6860)
successfully added.
```
### Remove Spanning Tree Configuration
```
$ nmcli con modify br0 bridge.stp no
```
### Bring Down previous Ethernet (Wireless or Cable-linked) Connection, associated with bridged interface (enp0s25 on this recipe):
```
$ nmcli con down wired-direct
```
### Bring Up the new Bridge Interface:
```
$ nmcli con up br0
```
### Restart NetworkManager Service
```
$ sudo systemctl restart NetworkManager.service
```
That's all if your Terraform scripts manage bridge interfaces creation and usage. In case you are using libvirt from command-line, without automations:
### Verify current Networks on Libvirt:
```
$ virsh net-list --all
Name State Autostart Persistent
----------------------------------------------------------
default active yes yes
```
### Create a New Network Interface
```
$ cat > bridge.xml <<EOF
<network>
<name>host-bridge</name>
<forward mode="bridge"/>
<bridge name="br0"/>
</network>
EOF
$ virsh net-define bridge.xml
Network host-bridge defined from bridge.xml
```
### Start New Interface and Setup it for Autostart:
```
$ virsh net-start host-bridge
Network host-bridge started
$ virsh net-autostart host-bridge
Network host-bridge marked as autostarted
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment