ubuntu:kvm:install_and_configure_kvm
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
ubuntu:kvm:install_and_configure_kvm [2020/08/10 22:48] – 192.168.1.1 | ubuntu:kvm:install_and_configure_kvm [2020/08/10 23:33] (current) – 192.168.1.1 | ||
---|---|---|---|
Line 26: | Line 26: | ||
</ | </ | ||
- | returns | + | returns: |
<code bash> | <code bash> | ||
Line 59: | Line 59: | ||
---- | ---- | ||
+ | ===== Setup Bridge networking with KVM ===== | ||
+ | A bridged network shares the real network interface of the host computer with other VMs to connect to the outside network. | ||
+ | |||
+ | By default KVM setups a private virtual bridge, so that all VMs can communicate with one another, within the host computer. | ||
+ | |||
+ | Have a look at the IP address of the KVM default virtual interfaces using the **ip** command: | ||
+ | |||
+ | <code bash> | ||
+ | ip a | ||
+ | </ | ||
+ | |||
+ | returns: | ||
+ | |||
+ | <code bash> | ||
+ | 1: lo: < | ||
+ | link/ | ||
+ | inet 127.0.0.1/8 scope host lo | ||
+ | | ||
+ | inet6 ::1/128 scope host | ||
+ | | ||
+ | 2: enp4s0: < | ||
+ | link/ether b4: | ||
+ | 3: enp3s0: < | ||
+ | link/ether b4: | ||
+ | 4: br0: < | ||
+ | link/ether b4: | ||
+ | inet 192.168.1.69/ | ||
+ | | ||
+ | inet6 fe80:: | ||
+ | | ||
+ | 5: wlp5s0: < | ||
+ | link/ether d0: | ||
+ | 6: virbr0: < | ||
+ | link/ether 52: | ||
+ | inet 192.168.122.1/ | ||
+ | | ||
+ | 7: virbr0-nic: < | ||
+ | link/ether 52: | ||
+ | </ | ||
+ | |||
+ | **NOTE: | ||
+ | |||
+ | The KVM default network **virbr0** uses 192.168.122.1/ | ||
+ | |||
+ | This is OK if you only access the VMs inside from the host itself. | ||
---- | ---- | ||
+ | |||
+ | ===== Disable Netfilter (optional) ===== | ||
+ | |||
+ | You could disable Netfilter for performance and security reasons. | ||
+ | |||
+ | To disable netfilter, create a file called **/ | ||
<code bash> | <code bash> | ||
+ | sudo vi / | ||
</ | </ | ||
+ | |||
+ | Add the following lines: | ||
+ | |||
+ | <file bash / | ||
+ | net.bridge.bridge-nf-call-ip6tables=0 | ||
+ | net.bridge.bridge-nf-call-iptables=0 | ||
+ | net.bridge.bridge-nf-call-arptables=0 | ||
+ | </ | ||
+ | |||
+ | Save and close the file. | ||
+ | |||
+ | Then create another file called **/ | ||
+ | |||
+ | <code bash> | ||
+ | sudo vi / | ||
+ | </ | ||
+ | |||
+ | Add the following line: | ||
+ | |||
+ | <file bash / | ||
+ | ACTION==" | ||
+ | </ | ||
+ | |||
+ | This will set the necessary flags to disable netfilter on bridges at the appropriate place in system start-up. Save and close the file. | ||
+ | |||
+ | Reboot your system to take effect these changes. | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Disable the default networking that KVM installed for itself ===== | ||
+ | |||
+ | Find the name of KVM default network interfaces using **ip link** command: | ||
+ | |||
+ | <code bash> | ||
+ | ip link | ||
+ | </ | ||
+ | |||
+ | returns: | ||
+ | |||
+ | <code bash> | ||
+ | 1: lo: < | ||
+ | link/ | ||
+ | 2: enp4s0: < | ||
+ | link/ether b4: | ||
+ | 3: enp3s0: < | ||
+ | link/ether b4: | ||
+ | 4: br0: < | ||
+ | link/ether b4: | ||
+ | 5: wlp5s0: < | ||
+ | link/ether d0: | ||
+ | 6: virbr0: < | ||
+ | link/ether 52: | ||
+ | 7: virbr0-nic: < | ||
+ | link/ether 52: | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | </ | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Remove the default KVM network ===== | ||
+ | |||
+ | <code bash> | ||
+ | virsh net-destroy default | ||
+ | </ | ||
+ | |||
+ | returns: | ||
+ | |||
+ | <code bash> | ||
+ | Network default destroyed | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Undefine the default network ===== | ||
+ | |||
+ | <code bash> | ||
+ | virsh net-undefine default | ||
+ | </ | ||
+ | |||
+ | returns: | ||
+ | |||
+ | <code bash> | ||
+ | Network default has been undefined | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | |||
+ | <code bash> | ||
+ | sudo ip link delete virbr0 type bridge | ||
+ | sudo ip link delete virbr0-nic | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Verify that the virbr0 and virbr0-nic interfaces are actually deleted ===== | ||
+ | |||
+ | |||
+ | <code bash> | ||
+ | ip link | ||
+ | </ | ||
+ | |||
+ | returns: | ||
+ | |||
+ | <code bash> | ||
+ | 1: lo: < | ||
+ | link/ | ||
+ | 2: enp4s0: < | ||
+ | link/ether b4: | ||
+ | 3: enp3s0: < | ||
+ | link/ether b4: | ||
+ | 4: br0: < | ||
+ | link/ether b4: | ||
+ | 5: wlp5s0: < | ||
+ | link/ether d0: | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Setup the KVM public bridge to use when creating a new VM ===== | ||
+ | |||
+ | <WRAP important> | ||
+ | **WARNING: | ||
+ | |||
+ | Most wireless interlaces do not support bridging. | ||
+ | |||
+ | Always use wired network interfaces for seamless connectivity! | ||
+ | |||
+ | </ | ||
+ | |||
+ | To create a network bridge in host, edit **01-network-manager-all.yaml** file and add the bridge details. | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE:** Before editing this file, back it up. | ||
+ | |||
+ | <code bash> | ||
+ | sudo cp / | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | Now edit similar to the following. | ||
+ | |||
+ | <file bash 01-network-manager-all.yaml> | ||
+ | Let NetworkManager manage all devices on this system | ||
+ | #network: | ||
+ | # version: 2 | ||
+ | # renderer: NetworkManager | ||
+ | |||
+ | # Let NetworkManager manage all devices on this system | ||
+ | network: | ||
+ | version: 2 | ||
+ | #renderer: NetworkManager | ||
+ | renderer: networkd | ||
+ | ethernets: | ||
+ | enp3s0: | ||
+ | dhcp4: no | ||
+ | # disable existing configuration for ethernet | ||
+ | #addresses: [192.168.1.69/ | ||
+ | #gateway4: 192.168.1.1 | ||
+ | # | ||
+ | #addresses: [192.168.1.1] | ||
+ | dhcp6: no | ||
+ | |||
+ | # add configuration for bridge interface | ||
+ | bridges: | ||
+ | br0: | ||
+ | interfaces: [enp3s0] | ||
+ | dhcp4: no | ||
+ | addresses: [192.168.1.69/ | ||
+ | gateway4: 192.168.1.1 | ||
+ | nameservers: | ||
+ | addresses: [192.168.1.1, | ||
+ | parameters: | ||
+ | # stp: false | ||
+ | stp: true | ||
+ | forward-delay: | ||
+ | dhcp6: no | ||
+ | </ | ||
+ | |||
+ | After modifying the network config file, save and close it. | ||
+ | |||
+ | Apply the changes by running the following command: | ||
+ | |||
+ | <code bash> | ||
+ | sudo netplan --debug | ||
+ | </ | ||
+ | |||
+ | Now check if the IP address has been assigned to the bridge interface: | ||
+ | |||
+ | <code bash> | ||
+ | ip a | ||
+ | </ | ||
+ | |||
+ | returns: | ||
+ | |||
+ | <code bash> | ||
+ | 1: lo: < | ||
+ | link/ | ||
+ | inet 127.0.0.1/8 scope host lo | ||
+ | | ||
+ | inet6 ::1/128 scope host | ||
+ | | ||
+ | 2: enp4s0: < | ||
+ | link/ether b4: | ||
+ | 3: enp3s0: < | ||
+ | link/ether b4: | ||
+ | 4: br0: < | ||
+ | link/ether b4: | ||
+ | inet 192.168.1.69/ | ||
+ | | ||
+ | inet6 fe80:: | ||
+ | | ||
+ | 5: wlp5s0: < | ||
+ | link/ether d0: | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Show the Bridge Status ===== | ||
+ | |||
+ | <code bash> | ||
+ | brctl show br0 | ||
+ | </ | ||
+ | |||
+ | returns: | ||
+ | |||
+ | <code bash> | ||
+ | bridge name bridge id STP enabled interfaces | ||
+ | br0 8000.b42e993ee522 yes enp3s0 | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Configure KVM to use the bridge ===== | ||
+ | |||
+ | Create a an XML file called **bridge.xml**. | ||
+ | |||
+ | Add the following lines: | ||
+ | |||
+ | <file bash bridge.xml> | ||
+ | < | ||
+ | < | ||
+ | <forward mode=" | ||
+ | <bridge name=" | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | Start the newly created bridge and make it as default bridge for VMs. | ||
+ | |||
+ | <code bash> | ||
+ | virsh net-define bridge.xml | ||
+ | </ | ||
+ | |||
+ | returns: | ||
+ | |||
+ | <code bash> | ||
+ | Network br0 defined from bridge.xml | ||
+ | </ | ||
+ | |||
+ | |||
+ | Start the bridge. | ||
+ | |||
+ | <code bash> | ||
+ | virsh net-start br0 | ||
+ | </ | ||
+ | |||
+ | returns: | ||
+ | |||
+ | <code bash> | ||
+ | Network br0 started | ||
+ | </ | ||
+ | |||
+ | Configure the bridge to autostart each time the system reboots. | ||
+ | |||
+ | < | ||
+ | virsh net-autostart br0 | ||
+ | </ | ||
+ | |||
+ | returns | ||
+ | |||
+ | <code bash> | ||
+ | Network br0 marked as autostarted | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Verify that the bridge is active and started ===== | ||
+ | |||
+ | <code bash> | ||
+ | virsh net-list --all | ||
+ | </ | ||
+ | |||
+ | returns: | ||
+ | |||
+ | <code bash> | ||
+ | | ||
+ | ----------------------------------------- | ||
+ | | ||
+ | </ | ||
+ | |||
+ | <WRAP info> | ||
+ | **NOTE: | ||
+ | </ | ||
+ | |||
+ |
ubuntu/kvm/install_and_configure_kvm.1597099718.txt.gz · Last modified: 2020/08/10 22:48 by 192.168.1.1