Libvirt: Difference between revisions
imported>13x1 Change `services` -> `virtualisation` because `libvirtd` is there now. See https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/virtualisation/libvirtd.nix |
imported>Onny Add bridge networking example |
||
Line 48: | Line 48: | ||
If you would like to enable nested virtualization for your guests to run KVM hypervisors inside them, you should enable it as follows: {{nixos:option|boot.extraModprobeConfig}}, for example: | If you would like to enable nested virtualization for your guests to run KVM hypervisors inside them, you should enable it as follows: {{nixos:option|boot.extraModprobeConfig}}, for example: | ||
{{file|/etc/nixos/configuration.nix|xml|<nowiki> | |||
boot.extraModprobeConfig = "options kvm_intel nested=1"; | |||
</nowiki>}} | |||
=== Bridge networking === | |||
Create a XML file with the definition of the bridge interface | |||
{{file|virbr0.xml|nix|<nowiki> | |||
<network> | |||
<name>virbr0</name> | |||
<forward mode='bridge'/> | |||
<bridge name='virbr0'/> | |||
</network> | |||
</nowiki>}} | |||
Add and enable bridge interface | |||
<syntaxhighlight lang="bash"> | |||
virsh net-define virbr0.xml | |||
virsh net-start virbr0 | |||
ip link add virbr0 type bridge | |||
ip address ad dev virbr0 10.25.0.1/24 | |||
ip link set dev virbr0 up | |||
</syntaxhighlight> | |||
Edit the libvirt guest <code>my_guest</code> XML file and add the bridge interface to it | |||
<syntaxhighlight lang="bash"> | |||
virsh edit my_guest | |||
</syntaxhighlight> | |||
Add | |||
{{file|my_guest.xml|nix|<nowiki> | |||
<devices> | |||
[...] | |||
<interface type='bridge'> | |||
<mac address='52:54:00:12:34:56'/> | |||
<source bridge='virbr0'/> | |||
<model type='virtio'/> | |||
<address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/> | |||
</interface> | |||
[...] | |||
</devices> | |||
</nowiki>}} | |||
Inside the guest configure networking for the interface <code>enp1s0</code> (name might differ) | |||
{{file|/etc/nixos/configuration.nix|nix|<nowiki> | {{file|/etc/nixos/configuration.nix|nix|<nowiki> | ||
networking.interfaces.enp1s0.ipv4.addresses = [{ | |||
address = "10.25.0.2"; | |||
prefixLength = 24; | |||
}]; | |||
</nowiki>}} | </nowiki>}} | ||
The host should now be able to reach the guest via the bridge interface and vice versa. | |||
== Clients == | == Clients == |