diff --git a/docs/posts/add-kvm-network-with-virsh.md b/docs/posts/add-kvm-network-with-virsh.md new file mode 100644 index 0000000..411265d --- /dev/null +++ b/docs/posts/add-kvm-network-with-virsh.md @@ -0,0 +1,114 @@ +--- +title: "Add KVM Network With Virsh" +date: 2021-10-16 +draft: false +tags: ["linux", "kvm", "libvirt", "virsh"] +authors: ["trent"] +post: 25 +--- +date: 2021-10-16 + +## Introduction +This is a short and sweet walk-through for how to create +a new network for `libvirt` for `kvm`, from the command line, +using `virsh`. + +## Name Resolution +Let's start with name resolution. + +* Install `libnss-libvirt`: +```shell +apt install libnss-libvirt +``` + +* In `/etc/nsswitch.conf`, add `libvirt` to hosts key. +```cfg +# /etc/nsswitch.conf +# change this +... +hosts: files dns mymachines +... +# to this +... +hosts: files libvirt dns mymachines +... +``` + +## Starter XML +You could dumpxml on the existing _default_ network: +```shell +virsh net-dumpxml default > foonet.xml +``` +Then, edit foonet.xml: + +* remove the network uuid +* change the network name to taste +* remove the bridge mac +* change the bridge name to taste +* change the bridge ip address and dhcp range to taste + +```xml + + + foonet + + + + + + + + + + + + +``` + +## Define The Network +With the above xml file: `virsh net-define foonet.xml` + +The network definition can now be found in `/etc/libvirt/qemu/networks/foonet.xml` +```xml + + + + + foonet + e6e40bfc-d449-4043-924c-ca0f0edf4210 + + + + + + + + + + + + + +``` + +You could also start the network without defining it +using `virsh net-create foonet.xml`. + +## Start/Stop +* Start the network + * `virsh net-start foonet` +* Stop the network + * `virsh net-destroy foonet` +* Undefine the network + * `virsh net-undefine foonet` +* Autostart the network + * `virsh net-autostart foonet` +* Disable autostart for the network + * `virsh net-autostart foonet --disable` + +Tab completion is you friend! diff --git a/mkdocs.yml b/mkdocs.yml index ee76aad..dd7142a 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -24,6 +24,7 @@ markdown_extensions: nav: - Home: - Home: index.md + - "Add KVM Network With Virsh": posts/add-kvm-network-with-virsh.md - "KVM On Arch": posts/kvm-on-arch.md - "RaspberryPi LTE-Failover Router With DNS Caching": posts/raspberrypi-lte-failover-router-with-dns-caching.md - "Flutter Integration Test Server in Debian 11 Nspawn Container": posts/debian-11-nspawn-flutter-integration-test-server.md @@ -62,6 +63,7 @@ nav: - FreeCodeCampChallenges: https://trentspalmer.github.io/fcc-challenges/ - DeviceLayout: https://trentpalmer.work/6a57bbe24d8244289610bf57533d6c6f/ - Posts: + - "Add KVM Network With Virsh": posts/add-kvm-network-with-virsh.md - "KVM On Arch": posts/kvm-on-arch.md - "RaspberryPi LTE-Failover Router With DNS Caching": posts/raspberrypi-lte-failover-router-with-dns-caching.md - "Flutter Integration Test Server in Debian 11 Nspawn Container": posts/debian-11-nspawn-flutter-integration-test-server.md