1

I'm setting up a KVM virtualization server in CentOS 6. How do I configure bridged networking? (I think I need network interface eth0 to be accessible to VMs)

I have tried to follow this guide:

How To Install KVM And libvirt On CentOS 6.2 With Bridged Networking

by modifying /etc/sysconfig/network-scripts/ifcfg-br0 with the values appropriate for my network:

DEVICE="br0"
TYPE=Bridge
DELAY=0
ONBOOT="yes"
BOOTPROTO=static
IPADDR=178.126.193.153
NETMASK=255.255.255.192
NETWORK=178.126.193.128
GATEWAY=178.126.193.190
DNS1=37.58.58.137
DNS2=91.109.25.225
PEERDNS="yes"
NM_CONTROLLED=no

and adding the following lines to /etc/sysconfig/network-scripts/ifcfg-eth0:

BRIDGE=br0
NM_CONTROLLED=no

Maybe I shouldn't be adding, but instead write only the lines outlined in the guide? I'm not sure what the NETWORK value is supposed to be, and if I set it right and whether it matters.

Anyway, when I did service network restart I was locked out of the server and I have to ask my hosting provider's support to reinstall it. Is there a 'bulletproof' way to set up a bridge, that is not that easy to screw up? Like e.g. this Debian example I found:

brctl addbr br0
2

How about this way I found in RHEL documentation:

virsh iface-bridge eth0 br0

then, of course, restart the networking service:

sudo service network restart

and verify the bridge config:

brctl show

For me, it shows 'brctl show' shows 2 bridges: br0 and virbr0

I didn't expect virbr0 to appear, but it turns out that virbr0 ("Virtual Bridge 0") interface is used by guests that are set up to use NAT networking; it is deliberately set up by default to use 192.168.122.0/24 as its subnet and includes its own dhcp server and uses dnsmasq for DNS resolution.

It is used for NAT (Network Address Translation) and is provided by the libvirt library, and virtual environments sometimes use it to connect to the outside network.

I am going to leave it, at this is exactly what I needed: I want some VMs to be able to access the internet directly (I have IP's for those) while the other VM's will access the internet via NAT. But if one is certain that the extra bridge won't be needed, virbr0 can be removed by

brctl delbr virbr0
  • That looks reasonable. Did it work? – Michael Hampton Mar 28 '14 at 0:07
  • @Michael Will have to wait for the server to reinstall. There is a process to do this automatically, but 1) it doesn't work 2) I would like to use a custom formatting anyway (LVM+RAID1) so I have to file tickets and excercise the patience of ever-tolerant tech support. – Nickolai Leschov Mar 28 '14 at 1:03
  • @Michael Finally reinstalled and tried this. It works, doesn't lock me out and persists across reboots. Also, it adds another bridge, which looks like what I wanted all along! I have updated my answer with the details. – Nickolai Leschov Apr 2 '14 at 22:40
0

To make the configuration persistent, you will have to edit the config files. You don't really need the NETWORK part of you have an IPADDR, NETMASK and GATEWAY set up.

The ifcfg-eth0 script should contain the following:

DEVICE="eth0"
HWADDR=AA:BB:CC:DD:11:22
TYPE=Ethernet
ONBOOT="yes"
BOOTPROTO=none
BRIDGE=br0

To make sure you aren't locked out, you can set up a script that resets the network back to a working configuration every 20 minutes or so, put that in cron, and hack away. If you get locked out, all you need to do is wait for the script to restore a working configuration.

  • The script like that would be wonderful! How would I go about writing it, or maybe there's a ready made one? – Nickolai Leschov Mar 27 '14 at 23:08
  • copy the working scripts to another folder and run an overwrite command every few minutes through cron, add service network restart at the end and your script is ready – dyasny Mar 28 '14 at 3:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.