CentOS 7: KVM Installation and Bridge networking

CentOS 7: KVM Installation and Bridge networking
            

Stop and disable the NetworkManager service, because we don’t need it on the server:

sudo systemctl stop NetworkManager 
sudo systemctl disable NetworkManager


sudo service network restart

Setting up a Static IP Address on CentOS 7

         




In this case I want it to have the IP 192.168.2.100.
Interestingly, although I have a network interface enp0s7:
ifconfig enp0s7

Output:
enp0s7: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.10  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::21e:90ff:fe77:865c  prefixlen 64  scopeid 0x20<link>
        ether 00:1e:90:77:86:5c  txqueuelen 1000  (Ethernet)
        RX packets 534  bytes 45293 (44.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 443  bytes 61545 (60.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

I don’t have a corresponding /etc/sysconfig/network-scripts/ifcfg-enp0s7 file to edit:
ls /etc/sysconfig/network-scripts/ifcfg-*

Output:
 
/etc/sysconfig/network-scripts/ifcfg-lo
 
So I’m going to go ahead and create one manually:
vim /etc/sysconfig/network-scripts/ifcfg-enp0s7
And add the following contents:
 
DEVICE="enp0s7"
ONBOOT="yes"
NM_CONTROLLED="no"
TYPE=Ethernet
BOOTPROTO=static
IPADDR=192.168.2.100
NETMASK=255.255.255.0
GATEWAY=192.168.2.1
 
Then to make the changes take, I’ll issue a:
service network restart
 
Since I was smart enough to do this over SSH (oops) my SSH session disconnected - luckily everything worked and now I can SSH to the new address:

ssh root@192.168.2.100
Warning: Permanently added '192.168.2.100' (ECDSA) to the list of known hosts.
root@192.168.2.100's password:
Last login: Sun Aug 24 12:22:13 2014 from 192.168.2.3
 
Check ifconfig again:
ifconfig enp0s7
enp0s7: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.100  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::21e:90ff:fe77:865c  prefixlen 64  scopeid 0x20<link>
        ether 00:1e:90:77:86:5c  txqueuelen 1000  (Ethernet)
        RX packets 937  bytes 81673 (79.7 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 723  bytes 96449 (94.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 
Reboot the system to be 100% certain that this is permanent:
reboot
SSHing in to the system at 192.168.2.100 worked without issue and ifconfig confirms this:
ifconfig enp0s7
enp0s7: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.100  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::21e:90ff:fe77:865c  prefixlen 64  scopeid 0x20<link>
        ether 00:1e:90:77:86:5c  txqueuelen 1000  (Ethernet)
        RX packets 56  bytes 7349 (7.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 70  bytes 10412 (10.1 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
Now that CentOS 7 is installed and has a static IP address, I’ll go ahead and install KVM.
First you’ll want to check if your processor/motherboard has the necessary extensions:
egrep -i 'vmx|svm' --color=always /proc/cpuinfo | sort | uniq
Output:

flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca ....

Now let’s install the tools - note that I also include the ifconfig package and the bind-utils (for the dig command)

#yum -y install qemu-kvm libvirt virt-install bridge-utils ifconfig bind-utils
 
 If you want to manage KVM with the graphical Interface :
 
#yum install virt-manager

Start the libvirtd service:

#systemctl start libvirtd

Set it to start automatically on every boot:

#systemctl enable libvirtd 

Note: My router is 192.168.2.1
The KVM host is: 192.168.2.100

You’ll notice that you also have a virbr0 device which already has an IP - you can ignore this one as we’re adding a different interface (bridge0)

ifconfig virbr0
virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether d2:55:3d:b6:5b:d5  txqueuelen 0  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Now configure networking - in my case this is the configuration of my original device /etc/sysconfig/network-scripts/ifcfg-eth0-backup

cat /etc/sysconfig/network-scripts/ifcfg-enp0s7
DEVICE="enp0s7"
ONBOOT="yes"
NM_CONTROLLED="no"
TYPE=Ethernet
BOOTPROTO=static
IPADDR=192.168.2.100
NETMASK=255.255.255.0
GATEWAY=192.168.2.1

I commented out the networking configuration parts and added the BRIDGE. The configuration parts will be moved to the bridge interface - the end result looks like this:

cat /etc/sysconfig/network-scripts/ifcfg-enp0s7
DEVICE="enp0s7"
ONBOOT="yes"
NM_CONTROLLED="no"
#TYPE=Ethernet
BRIDGE=bridge0
BOOTPROTO=static
#IPADDR=192.168.2.100
#NETMASK=255.255.255.0
#GATEWAY=192.168.2.1

And this is the bridge file I added:

cat /etc/sysconfig/network-scripts/ifcfg-bridge0
DEVICE="bridge0"
ONBOOT="yes"
TYPE=Bridge
BOOTPROTO=static
IPADDR=192.168.2.100
NETMASK=255.255.255.0

Note that the GATEWAY line is gone from both enp0s7 AND bridge0 - this should go into /etc/sysconfig/network

cat /etc/sysconfig/network
# Created by anaconda
GATEWAY=192.168.2.1

Now issue a service network restart:

service network restart
Restarting network (via systemctl):                        [  OK  ]

The result should look like this - the enp0s7 interface:

ifconfig enp0s7
enp0s7: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::21e:90ff:fe77:865c  prefixlen 64  scopeid 0x20<link>
        ether 00:1e:90:77:86:5c  txqueuelen 1000  (Ethernet)
        RX packets 804  bytes 103470 (101.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 475  bytes 61930 (60.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

The bridge0 interface:

ifconfig bridge0
bridge0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.100  netmask 255.255.255.0  broadcast 192.168.2.255
        inet6 fe80::21e:90ff:fe77:865c  prefixlen 64  scopeid 0x20<link>
        ether 00:1e:90:77:86:5c  txqueuelen 0  (Ethernet)
        RX packets 398  bytes 27098 (26.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 250  bytes 32824 (32.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

The router should be pingable:

ping -c 1 192.168.2.1
PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data.
64 bytes from 192.168.2.1: icmp_seq=1 ttl=64 time=3.73 ms

--- 192.168.2.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 3.732/3.732/3.732/0.000 ms

DNS should be resolving - couple of quick tests:

dig www.google.com +short
173.194.33.84
173.194.33.80
173.194.33.82
173.194.33.83
173.194.33.81

dig www.weirdbricks.com +short
lampros.chaidas.com.
69.172.229.155

Comentarios

  1. Followed you guide works great for 1 nic and a bridge but i have 2 nics where 1 is local lan and 2 is public static ips
    how do you add a second bridge w/o messing up the routing of the host and the guests on the local lan ?

    ResponderEliminar
  2. Followed you guide works great for 1 nic and a bridge but i have 2 nics where 1 is local lan and 2 is public static ips
    how do you add a second bridge w/o messing up the routing of the host and the guests on the local lan ?

    ResponderEliminar
  3. FANTASTIC!! Thank you sooo much! I have spent 5 days messing about with this, trying to setup a KVM bridge... yours are the first instructions which actually WORK!....... I need to go and lie down quietly somewhere now..... :)

    ResponderEliminar

Publicar un comentario