[SOLVED] libvirt network bridge

Issues related to configuring your network
Post Reply
TheEffigy
Posts: 3
Joined: 2011/11/11 12:49:38

[SOLVED] libvirt network bridge

Post by TheEffigy » 2011/11/11 13:07:31

So I've started tinkering with libvirt and I've found that creating a virtual machine was a no-brainer, but getting the networking to play nice hasn't been so straight forward.

On debian I haven't had any issues, but on centos I just can't manage to get it going.

Perhaps someone can help me out here.

I configured the virtual instance to use bridge0:
[code]
<interface type='bridge'>
<mac address='52:54:00:ea:9a:46'/>
<source bridge='bridge0'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
[/code]

And I have setup ifcfg-bridge0 thusly:
[code]
DEVICE="bridge0"
TYPE="Bridge"
BOOTPROTO="dhcp"
ONBOOT="yes"
[/code]

ifcfg-eth0 has been modified:
[code]
DEVICE="eth0"
HWADDR="00:1D:09:8A:D4:8B"
ONBOOT="yes"
BOOTPROTO="none"
IPADDR="192.168.2.2"
NETMASK="255.255.255.0"
DNS1="192.168.2.1"
GATEWAY="192.168.2.1"
[b]BRDIGE="bridge0"[/b]
[/code]

My test instance can't access the network at all unfortunately, any clues?

User avatar
toracat
Forum Moderator
Posts: 7434
Joined: 2006/09/03 16:37:24
Location: California, US
Contact:

[SOLVED] libvirt network bridge

Post by toracat » 2011/11/11 17:42:29

[quote]
BRDIGE="bridge0"

My test instance can't access the network at all unfortunately, any clues?[/quote]
Perhaps, start troubleshooting by correcting the typo? BRDIGE -> BRIDGE

TheEffigy
Posts: 3
Joined: 2011/11/11 12:49:38

Re: libvirt network bridge

Post by TheEffigy » 2011/11/12 04:54:51

Gah, don't know how I missed that! So the bridge is up now, but I still can't get the instance to see connect to the network. It can see an interface, just can't seem to configure it.

larwood
Posts: 60
Joined: 2011/07/27 12:07:30
Location: Perth WA, Australia

Re: libvirt network bridge

Post by larwood » 2011/11/13 10:38:26

You have to put the gateway etc. in the bridge config and modify iptabes. Here is my setup:

# cat /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
BOOTPROTO=none
ONBOOT=yes
DELAY=0
IPADDR0=10.1.1.10
PREFIX0=8
DNS1=10.1.1.17
IPV6INIT=no
USERCTL=no

# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
HWADDR=E0:CB:4E:24:F9:26
BRIDGE=br0

# iptables -I FORWARD -m physdev --physdev-is-bridged -j ACCEPT
# /etc/init.d/iptables save
# /etc/init.d/iptables restart

Check gateway is configured and if not:
# route add default gw 10.1.1.1
# echo “GATEWAY=10.1.1.1 ” >> /etc/sysconfig/network

I found that this introduced a 60 second delay on login, which for me was caused sendmail timing out on boot.
Fix was to ensure hostname is present in hosts file:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 serverhostname
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 serverhostname

User avatar
jlehtone
Posts: 2888
Joined: 2007/12/11 08:17:33
Location: Finland

Re: libvirt network bridge

Post by jlehtone » 2011/11/14 11:50:43

[quote]larwood wrote:
You have to put the gateway etc. in the bridge config and modify iptabes.[/quote]
I don't think so.

First, the host needs no IP address on the physical interface or on the bridge for
the guest network to function. The bridge passes everything to its interfaces and
thus traffic from the guest is thrown out from the physical interface too.

It would be different, if traffic between virtual machines and the physical net would
be routed.


Second, at least on my C6 installations, the /etc/sysctl.conf explicitly disables netfilter
on bridged packets. Therefore, iptables should never see traffic between guests and
outside. Again, routed network is a different matter.



Therefore:
* "brctl show" on host reveals the bridge0 to have two slaves, eth0 and vnet?
* How has the guest configured its interface?

TheEffigy
Posts: 3
Joined: 2011/11/11 12:49:38

Re: libvirt network bridge

Post by TheEffigy » 2011/11/14 13:07:47

Cheers for the input guys - much appreciated, it's all working great now. I think my problem was actually (spelling mistake aside) in how I modified the guest instance configuration XML. I modified /etc/libvirt/qemu/foo.xml but it didn't seem to work, modifying via virsh edit seemed to have done the trick.

User avatar
jlehtone
Posts: 2888
Joined: 2007/12/11 08:17:33
Location: Finland

Re: libvirt network bridge

Post by jlehtone » 2011/11/14 13:19:21

[quote]TheEffigy wrote:
I modified /etc/libvirt/qemu/foo.xml but it didn't seem to work, modifying via virsh edit seemed to have done the trick.[/quote]
I think that the libvirtd keeps in memory all of the configuration (that it reads on start). "virsh edit" or "virt-manager" tools edit the in-memory copy and then save to file too. An alternative is to edit the file and then do "virsh define foo.xml", which overwrites the in-memory copy.

pschaff
Retired Moderator
Posts: 18276
Joined: 2006/12/13 20:15:34
Location: Tidewater, Virginia, North America
Contact:

Re: [SOLVED] libvirt network bridge

Post by pschaff » 2011/11/15 00:42:09

Thanks for reporting back. Marking this thread [SOLVED] for posterity.

Post Reply

Return to “CentOS 6 - Networking Support”