Skip to content

Instantly share code, notes, and snippets.

@kekyo
Last active June 19, 2022 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kekyo/3a9bd962e84c03e5a4fef8493483f1be to your computer and use it in GitHub Desktop.
Save kekyo/3a9bd962e84c03e5a4fef8493483f1be to your computer and use it in GitHub Desktop.
Minimal configuration for libvirt environment with bridge interface on ubuntu 22.04 when using nmcli (without netplan)

Example network diagram

Before Configuring

                                    192.168.56.0/24
                                          |
                      192.168.56.1        |        192.168.56.17 (Wired connection 1)
                                |         v         |
The internet --- gateway router *-------------------* (enp1s0) *---- (... app sockets)
                                                   |
                                                   |------> Your machine

After configured

                                    192.168.56.0/24        (bridge-slave-enp1s0)
                                          |                         |
                      192.168.56.1        |                         |           192.168.56.17
                                |         v                         v            |
The internet --- gateway router *-------------------* (enp1s0) *---------* (br0) *---- (... app sockets)
                                                   |                         *      
                                                   |------> Your machine     |
                                                                             +---- (... libvirt VMs, could direct attachable and no need to NAT)

Step 1: Configure bridge interface

Show current connection definitions:

$ nmcli conn show
NAME                 UUID                                  TYPE      DEVICE 
Wired connection 1   baf0574f-34d5-30d4-8b65-a5bf1d06c85e  ethernet  enp1s0

$ ip a
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 12:34:56:62:90:90 brd ff:ff:ff:ff:ff:ff
    inet 192.168.56.17/24 brd 192.168.56.255 scope global noprefixroute enp1s0
      valid_lft forever preferred_lft forever

Define bridge interface and connects between bridge and physical interface:

$ nmcli conn add ifname br0 type bridge con-name br0
$ nmcli conn add type bridge-slave ifname enp1s0 master br0

Setup bridge interface attributes:

$ nmcli conn modify br0 ipv4.addresses 192.168.56.17/24
$ nmcli conn modify br0 ipv4.gateway 192.168.56.1
$ nmcli conn modify br0 ipv4.dns 192.168.56.1
$ nmcli conn modify br0 ipv4.method manual
$ nmcli conn up br0

Delete defaulted physical interface definition:

  • CAUTION: Running this command on ssh will be disconnected. You will need to reconnect after ran 1 minute or later.
$ nmcli conn delete baf0574f-34d5-30d4-8b65-a5bf1d06c85e

Review final definitions:

$ nmcli conn show
NAME                 UUID                                  TYPE      DEVICE 
br0                  f3e8eb0b-3b78-47ed-9797-153f19a05dc3  bridge    br0    
bridge-slave-enp1s0  8a69787b-5496-4771-8c14-e6a77c18b00c  ethernet  enp1s0 

$ ip a
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP group default qlen 1000
    link/ether 30:bf:00:62:90:90 brd ff:ff:ff:ff:ff:ff
3: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether e2:e1:5a:bb:ee:71 brd ff:ff:ff:ff:ff:ff
    inet 192.168.56.17/24 brd 192.168.56.255 scope global noprefixroute br0
       valid_lft forever preferred_lft forever
  • NOTE: Previously in Ubuntu versions, the NetworkManager GUI could be used to configure the bridge interface. However, as of Ubuntu 22.04, the NetworkManager GUI becomes useless after this configuration. Do not use the GUI to manipulate any network configurations.

Step 2: Configure libvirt for bridge interface

Place /etc/libvirt/qemu/networks/bridge-br0.xml:

<network>
  <name>bridge-br0</name>
  <forward mode="bridge" />
  <bridge name="br0" />
</network>

Then:

systemctl restart libvirtd

Done!


Cockpit-machines results

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment