KVM
Here are the steps needed to get KVM up and running.
EL7
-
Install dependencies
sudo yum install -y kvm virt-manager libvirt virt-install qemu-kvm libvirt-client virt-viewer bridge-utils
-
Enable IPv4 forwarding
echo "net.ipv4.ip_forward = 1"|sudo tee /etc/sysctl.d/99-ipforward.conf net.ipv4.ip_forward = 1 sudo sysctl -p /etc/sysctl.d/99-ipforward.conf net.ipv4.ip_forward = 1
-
Fix netowrk script for your ethernet device. This example will presume eno1 is your network device. Edit /etc/sysconfig/network-scripts/ifcfg-eno1 and remove anything that doesn't fit this example (we do not need any IPv4/IPv6 data here, just the HWADDR (MAC address) and the basic on-boot information.
DEVICE="eno1" NAME="Onboard Ethernet" ONBOOT=yes HWADDR="00:0c:29:32:d0:4c" BRIDGE=br0
-
Create bridge device. This is a new file we will create at /etc/sysconfig/network-scripts/ifcfg-br0. Edit the IPADDR, NETMASK, GATEWAY, and DNS lines to use a separate subnet to what you are using:
DEVICE="br0" NAME="Ethernet Bridge" TYPE=BRIDGE ONBOOT=yes BOOTPROTO=static IPADDR="10.0.0.2" NETMASK="255.0.0.0" GATEWAY="10.0.0.1" DNS1="10.0.0.1"
-
For dynamic IPs in your guests, setup KVM to use bridged networking or setup your bridge as follows:
DEVICE=br0 NAME="Ethernet Bridge" TYPE=Bridge BOOTPROTO=dhcp ONBOOT=yes DELAY=0
-
Add user(s) to libvirt group to manage VMs
sudo gpasswd libvirt -a USERNAME
-
Reboot to enable changes.
sudo systemctl reboot
RHEL 8+, FEDORA
-
Install dependencies
sudo dnf groupinstall "Virtualization" sudo dnf install qemu-img libvirt libvirt-python libvirt-client
-
Add user(s) to libvirt group to manage VMs
sudo gpasswd libvirt -a USERNAME
-
Reboot to enable changes
sudo systemctl reboot
UBUNTU
-
Install dependencies
sudo apt install -y qemu-kvm libvirt0 libvirt-bin virt-manager bridge-utils
-
Enable service
sudo systemctl enable libvirtd
-
Enable bridge (presuming ethernet adapter is eno1, change as needed)
cat <<EOF | sudo tee /etc/network/interfaces auto lo iface lo inet loopback auto br0 iface br0 inet dhcp bridge_ports eno1 bridge_stp off bridge_maxwait 0 EOF
-
Reboot to have settings take effect
sudo reboot
USE NETWORK MANAGER CLI (nmcli)
-
I personally move/vape the existing /etc/sysconfig/network-scripts/ifcfg-* and use nmcli to start fresh, just in case something isnt overwritten correctly. But to each their own.
-
Install needed packages
-
CREATE BRIDGE
nmcli con add type bridge con-name br0 ifname br0 autoconnect yes
-
ADD $ADAPTER TO BRIDGE
nmcli con add type ethernet con-name $ADAPTER ifname $ADAPTER master br0 autoconnect yes nmcli con mod br0 bridge.stp no
-
USE STATIC IP ON BRIDGE
nmcli con mod br0 ipv4.addresses 192.168.1.2/16 ipv4.method manual ipv4.gateway 192.168.1.1 ipv4.dns 8.8.8.8
-
USE DHCP ON BRIDGE
nmcli con mod br0 ipv4.method auto
USE NETWORK-MANAGER AS USER
-
Create a new group:
newgrp libvirt
-
Add the selected user to group
sudo usermod -a -G libvirt $USER
-
Edit /etc/libvirt/libvirtd.conf and change the following parameters to match:
unix_sock_group = "libvirt" unix_sock_rw_perms = "0770"
-
Restart daemon
sudo systemctl restart libvirtd.service