How do I configure bridged networking for VMs

18,764

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
Share:
18,764

Related videos on Youtube

Nickolai Leschov
Author by

Nickolai Leschov

I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched c-beams glitter in the dark near the Tanhauser Gate... Forget that. I've been working in the large gas power plant, a sprawling monster creeping over a city, large enough to power some European nations. A lake is kept warm in winter with just effluent waters. Everywhere you look in the city you can see traces of it. At any given time there's always something breaking or leaking somewhere. It looks like it can break down at any moment. Yet the constant labour of thousands of workers always keeps power plant humming along. It's an impressive feat of human engineering.

Updated on September 18, 2022

Comments

  • Nickolai Leschov
    Nickolai Leschov almost 2 years

    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
    
  • Nickolai Leschov
    Nickolai Leschov over 10 years
    The script like that would be wonderful! How would I go about writing it, or maybe there's a ready made one?
  • Michael Hampton
    Michael Hampton over 10 years
    That looks reasonable. Did it work?
  • David Corsalini
    David Corsalini about 10 years
    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
  • Nickolai Leschov
    Nickolai Leschov about 10 years
    @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.