How do I setup CentOS 7 for KVM Virtualisation with a bridged network [OVH/Hetzner]?


Coming from a minimal install the first step is to install the required software

# yum install net-tools qemu-kvm libvirt virt-install bridge-utils bind-utils

Convert the network configuration to a static IP address

Both Hetzner and OVH supply their dedicated servers were the network is configured via DHCP, this needs to be updated to a static configuration for the bridged network for KVM to work correctly.

To view the current network configuration run.

# ifconfig

With CentOS 7 the days of ethX are gone (unless it's OVH), they will now be labelled something like enp6s0

enp6s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.10.10.10  netmask 255.255.255.224  broadcast 176.9.36.255
        inet6 fe80::8e89:a5ff:fe63:b8ef  prefixlen 64  scopeid 0x20<link>
        ether 8c:89:a5:63:b8:ef  txqueuelen 1000  (Ethernet)
        RX packets 69106191  bytes 7806556849 (7.2 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 197727632  bytes 274850510321 (255.9 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

You will also need the gateway to setup the network.

# ip route

The output should have line prefixed with "default via".

default via 10.10.10.1 dev enp6s0  proto static  metric 1024

In the example above the default gateway is 10.10.10.1.

Replacing the name of your network device create a backup of the current network configuration (this must be a PREFIX otherwise it will be treated as a network device and will be configured on boot causing issues).

# cp /etc/sysconfig/network-scripts/ifcfg-enp6s0 /etc/sysconfig/network-scripts/bak.ifcfg-enp6s0

 Edit the configuration file (again replacing your network device name as required).

# vi /etc/sysconfig/network-scripts/ifcfg-enp6s0

You should see something like the following

# Generated by dracut initrd
DEVICE="enp6s0"
ONBOOT=yes
NETBOOT=yes
UUID="d2183429-2b16-43b1-99d6-433cf3c386ab"
IPV6INIT=yes
BOOTPROTO=dhcp
HWADDR="8c:89:a5:61:a8:ef"
TYPE=Ethernet
NAME="enp6s0"
DNS1="213.133.99.99"

 This needs to be changed to look like the following (dns shown are for Hetzner).

DEVICE="enp6s0"
ONBOOT=yes
NETBOOT=no
NM_CONTROLLED="no"
BOOTPROTO=static
HWADDR="8c:89:a5:61:a8:ef"
TYPE=Ethernet
NAME="enp6s0"
DNS1="213.133.98.98"
DNS2="213.133.99.99"
DNS3="213.133.100.100"
IPADDR=10.10.10.10
NETMASK=255.255.255.224
GATEWAY=10.10.10.1

Replacing the IPADDR/NETMASK with the inet initially shown on the network device, the GATEWAY IP from the output of  the "ip route" command.

Initially I would try restarting the network without a reboot 

# service network restart

If the network has been configured correctly the command prompt should return. If the command prompt doesn't come back you will need to boot the server in recovery mode and then either revert the changes from the bak file or correct any errors.

I would also advise doing reboot to ensure the network will start up like this as this is the basis of the network used later.

# reboot

Again if the server comes back after the reboot all is good, otherwise you will need to boot into recovery and resolve the issue.

Setup libvirt and configure the bridge

Start and enable libvirtd to start at system boot.

# systemctl start libvirtd
# systemctl enable libvirtd

Again we now need to copy the network file (changing the filename to your device as required) to make setting up the bridge network configration a little easier.

# cp /etc/sysconfig/network-scripts/ifcfg-enp6s0 /etc/sysconfig/network-scripts/ifcfg-br0

Edit the config for the network device.

# vi /etc/sysconfig/network-scripts/ifcfg-enp6s0

Comment out the HWADDR, TYPE, NAME, DNS1/DNS2/DNS3, IPADDR, NETMASK and GATEWAY and add the BRIDGE line which should leave you with something like this (we are calling the bridge to use with KVM "br0").

DEVICE="enp6s0"
ONBOOT=yes
NETBOOT=no
NM_CONTROLLED="no"
#BOOTPROTO=static #HWADDR="8c:89:a5:61:a8:ef" #TYPE=Ethernet #NAME="enp6s0" #DNS1="213.133.98.98" #DNS2="213.133.99.99" #DNS3="213.133.100.100" #IPADDR=10.10.10.10 #NETMASK=255.255.255.224 #GATEWAY=10.10.10.1
BRIDGE=br0

 And then edit the new file for the bridge configuration.

# vi /etc/sysconfig/network-scripts/ifcfg-br0

After updating the DEVICE, TYPE, NAME and comment out the GATEWAY you should have something like.

DEVICE="br0"
ONBOOT=yes
NM_CONTROLLED="no"
NETBOOT=no
IPV6INIT=yes
BOOTPROTO=static
#HWADDR="8c:89:a5:63:b8:ef"
TYPE=Bridge
NAME="br0"
DNS1="213.133.99.99"
IPADDR=10.10.10.10
NETMASK=255.255.255.224
#GATEWAY=10.10.10.1

You will now need to add the commented out GATEWAY line to your network configuration

# vi /etc/sysconfig/network

And add the removed GATEWAY line

GATEWAY=10.10.10.1

Once these fines have been updated and checked restart the network service

# service network restart

Now check your new bridge has the correct configuration with the following commans.

# ifconfig br0
# ifconfig enp6s0

The br0 device should now have the IP address and the enp6s0 device should have no IP address associated with it.

Once you are happy with the configuration reboot the server.

# reboot

If everything looks OK after reboot you can now proceed with your KVM system and setup new Virtual Servers (with virt-manager for example). If your server doesn't come back after a few minutes you will need to boot into recovery mode and check the configuration files.

Tags: 7, bridged, centos, centos7, kvm, network, virtualisation, vps
Last update:
2014-12-17 15:13
Author:
Chris Burton
Revision:
1.3
Average rating: 5 (1 Vote)

You cannot comment on this entry

Chuck Norris has counted to infinity. Twice.