Skip to main content

Command Palette

Search for a command to run...

setup the guest network in KVM to interact with the outside world

Published
2 min read
  1. Define a new bridge network in the host machine
sudo nano /etc/libvirt/qemu/networks/host-bridge.xml
<network>
  <name>host-bridge</name>
  <uuid>68c2cef1-3218-4fc5-901f-1393180d6e19</uuid>
  <forward mode='bridge'/>
  <bridge name='br0'/>
</network>

check if new network works

virsh net-list
networkctl status -a

config netplan

sudo nano /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
    enp1s0:
      dhcp4: false
      dhcp6: false
    ens1f0:
      dhcp4: true
    ens1f1:
      dhcp4: true
  bridges:
    br0:
      interfaces: [enp1s0]
      addresses:
         - 192.168.3.25/24
      gateway4: 192.168.3.1
      nameservers:
         addresses:
            - 8.8.4.4
            - 1.1.1.1
  version: 2

apply new config

sudo netplan apply
  1. redefine KVM guest, add new network interface
<interface type='bridge'>
      <mac address='52:54:00:bb:e7:99'/>
      <source bridge='br0'/>
      <target dev='vnet0'/>
      <model type='virtio'/>
      <alias name='net0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </interface>
  1. connect to the KVM guest and config netplan
network:
  version: 2
  renderer: networkd
  ethernets:
    ens2:
      dhcp4: yes
    ens9:
      dhcp4: false
      dhcp6: false
      addresses:
          - 192.168.3.28/24
      gateway4: 192.168.3.1
      nameservers:
          addresses: [8.8.4.4,1.1.1.1]

More from this blog

thuchoang

18 posts