how to configure linux bridge in the host side

  • install bridge-utils
apt install bridge-utils

  • add bridges and physical ports
brctl addbr virbr1
brctl addbr virbr2
brctl addif virbr1 eth4
brctl addif virbr2 eth5

  • add interface to VM
./newUbuntuVM.sh
virt-clone virt-clone -o base -n linux-bridge -f /var/lib/libvirt/images/linux-bridge.img
virsh
list --all
attach-interface --domain domID --type bridge --source virbr1 --model virtio --config --live
attach-interface --domain domID --type bridge --source virbr2 --model virtio --config --live
cat newUbuntuVM.sh
#!/bin/bash
#

if [ $# != 1 ]; then
    echo "Usage: $0 vmname"
    exit 1
fi

VMNAME=$1
OS_TYPE="linux"
OS_VARIANT="ubuntu16.04"
NUM_vCPUs="24"
RAM_SIZE="16384"
DISK_SIZE="16"
DISK_PATH="/var/lib/libvirt/images/${VMNAME}"
BRIDGE="virbr0"
URL='http://us.archive.ubuntu.com/ubuntu/dists/xenial/main/installer-amd64/'
OPT='console=ttyS0,115200n8 serial'

virt-install --accelerate --hvm \
    --name "$VMNAME" \
    --ram "$RAM_SIZE" \
    --disk path="$DISK_PATH".img,size="$DISK_SIZE" \
    --vcpus "$NUM_vCPUs" \
    --os-type "$OS_TYPE" \
    --os-variant "$OS_VARIANT" \
    --network bridge="$BRIDGE" \
    --graphics none \
    --console pty,target_type=serial \
    --location "$URL" \
    --extra-args "$OPT"
# you can edit XML for VM and reboot the VM
virsh 
list --all
edit domID
    <interface type='bridge'>
      <source bridge='virbr1'/>
      <model type='virtio'/>
    </interface>
    <interface type='bridge'>
      <source bridge='virbr2'/>
      <model type='virtio'/>
    </interface>

  • boot and configure VM
virsh start linux-bridge
virsh console domID
sudo vi /etc/sysctl.conf
net.ipv4.ip_forward=1
# if you cannot connect to console, refer to README.tips
# alternatively, below commands might be useful
virsh domnetlist domID
arp -n |grep domMAC
ssh ubuntu@domIP
vi /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0 net.ifnames=0"
update-grub
reboot

  • sample VM for 10G test
<domain type='kvm'>
  <name>xenial-lb</name>
  <uuid>41f0008b-96d9-4309-8474-212096e7f3a5</uuid>
  <memory unit='KiB'>4194304</memory>
  <currentMemory unit='KiB'>4194304</currentMemory>
  <memoryBacking>
    <hugepages>
      <page size='2048' unit='KiB' nodeset='0'/>
    </hugepages>
  </memoryBacking>
  <vcpu placement='static'>4</vcpu>
  <cputune>
    <shares>2048</shares>
    <vcpupin vcpu='0' cpuset='4'/>
    <vcpupin vcpu='1' cpuset='5'/>
    <vcpupin vcpu='2' cpuset='6'/>
    <vcpupin vcpu='3' cpuset='7'/>
  </cputune>
  <numatune>
    <memory mode='strict' nodeset='0'/>
    <memnode cellid='0' mode='strict' nodeset='0'/>
  </numatune>
  <os>
    <type arch='x86_64' machine='pc-i440fx-zesty'>hvm</type>
    <boot dev='hd'/>
  </os>
  <features>
    <acpi/>
    <apic/>
  </features>
  <cpu mode='host-passthrough'>
    <topology sockets='1' cores='4' threads='1'/>
    <numa>
      <cell id='0' cpus='0-3' memory='4194304' unit='KiB' memAccess='shared'/>
    </numa>
  </cpu>
  <clock offset='utc'>
    <timer name='rtc' tickpolicy='catchup'/>
    <timer name='pit' tickpolicy='delay'/>
    <timer name='hpet' present='no'/>
  </clock>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <pm>
    <suspend-to-mem enabled='no'/>
    <suspend-to-disk enabled='no'/>
  </pm>
  <devices>
    <emulator>/usr/bin/kvm-spice</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/home/mslee/work/CloudRouter/test/xenial-server-cloudimg-amd64-disk1-kairoson-certificate-clone.img'/>
      <target dev='vda' bus='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </disk>
    <controller type='usb' index='0' model='ich9-ehci1'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x7'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci1'>
      <master startport='0'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0' multifunction='on'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci2'>
      <master startport='2'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x1'/>
    </controller>
    <controller type='usb' index='0' model='ich9-uhci3'>
      <master startport='4'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x2'/>
    </controller>
    <controller type='pci' index='0' model='pci-root'/>
    <controller type='virtio-serial' index='0'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
    </controller>
    <interface type='bridge'>
      <mac address='52:54:00:f3:b9:7b'/>
      <source bridge='virbr0'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x0a' function='0x0'/>
    </interface>
    <interface type='bridge'>
      <mac address='52:54:00:32:07:a5'/>
      <source bridge='virbr1'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
    </interface>
    <interface type='bridge'>
      <mac address='52:54:00:64:8a:5c'/>
      <source bridge='virbr2'/>
      <model type='virtio'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
    </interface>
    <serial type='pty'>
      <target port='0'/>
    </serial>
    <console type='pty'>
      <target type='serial' port='0'/>
    </console>
    <channel type='spicevmc'>
      <target type='virtio' name='com.redhat.spice.0'/>
      <address type='virtio-serial' controller='0' bus='0' port='1'/>
    </channel>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='spice' autoport='yes'>
      <listen type='address'/>
      <image compression='off'/>
    </graphics>
    <sound model='ich6'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
    </sound>
    <video>
      <model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1' primary='yes'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    </video>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='1'/>
    </redirdev>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='2'/>
    </redirdev>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
    </memballoon>
  </devices>
</domain>

Leave a Reply

Your email address will not be published. Required fields are marked *