I have started using VMs more and more in my development workflow and it's impossible to work in a VM without an internet connection for me most of the time. Setting up the KVM networking is kind of confusing to me and I've done it two different ways. Here is how I set it up on my home desktop using NAT.


First thing's first: credit to this post


There was a default network already made by virt-manager but my VM couldn't connect over it at all...

These commands got me up and running without even turning the VM off

I went full on sudo -i for this just to make it easier - be careful

Dump an existint network config

# as root

virsh net-dumpxml default > br1.xml

vim br1.xml

Edit it

I was unsure what the ip range should be so I just stuck with the original blog. The default network had the CIDR block defined as which is different from my home network so I guess it's fine?

  <forward mode='nat'>
      <port start='1024' end='65535'/>
  <bridge name='br1' stp='on' delay='0'/>
  <ip address='' netmask=''>
      <range start='' end=''/>

Define a network

virsh net-define br1.xml
virsh net-autostart br1

Then to check...

virsh net-list --all

 Name      State    Autostart   Persistent
 br1       active   yes         yes
 default   active   yes         yes


virsh net-uuid br1


virsh attach-interface --domain <NAME OF VM> --type bridge --source br1 --model virtio --config --live

My VM, ubuntu20.04 was running and immediately connected to the newly attached device!

Credit again

Visit the original post for more details - this serves more as as a quicker set of notes for future me