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
virt-clone virt-clone -o base -n linux-bridge -f /var/lib/libvirt/images/linux-bridge.img
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

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

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
list --all
edit domID
    <interface type='bridge'>
      <source bridge='virbr1'/>
      <model type='virtio'/>
    <interface type='bridge'>
      <source bridge='virbr2'/>
      <model type='virtio'/>

  • boot and configure VM
virsh start linux-bridge
virsh console domID
sudo vi /etc/sysctl.conf
# if you cannot connect to console, refer to
# 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"

  • sample VM for 10G test
<domain type='kvm'>
  <memory unit='KiB'>4194304</memory>
  <currentMemory unit='KiB'>4194304</currentMemory>
      <page size='2048' unit='KiB' nodeset='0'/>
  <vcpu placement='static'>4</vcpu>
    <vcpupin vcpu='0' cpuset='4'/>
    <vcpupin vcpu='1' cpuset='5'/>
    <vcpupin vcpu='2' cpuset='6'/>
    <vcpupin vcpu='3' cpuset='7'/>
    <memory mode='strict' nodeset='0'/>
    <memnode cellid='0' mode='strict' nodeset='0'/>
    <type arch='x86_64' machine='pc-i440fx-zesty'>hvm</type>
    <boot dev='hd'/>
  <cpu mode='host-passthrough'>
    <topology sockets='1' cores='4' threads='1'/>
      <cell id='0' cpus='0-3' memory='4194304' unit='KiB' memAccess='shared'/>
  <clock offset='utc'>
    <timer name='rtc' tickpolicy='catchup'/>
    <timer name='pit' tickpolicy='delay'/>
    <timer name='hpet' present='no'/>
    <suspend-to-mem enabled='no'/>
    <suspend-to-disk enabled='no'/>
    <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'/>
    <controller type='usb' index='0' model='ich9-ehci1'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x7'/>
    <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 type='usb' index='0' model='ich9-uhci2'>
      <master startport='2'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x1'/>
    <controller type='usb' index='0' model='ich9-uhci3'>
      <master startport='4'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x2'/>
    <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'/>
    <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 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 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'/>
    <serial type='pty'>
      <target port='0'/>
    <console type='pty'>
      <target type='serial' port='0'/>
    <channel type='spicevmc'>
      <target type='virtio' name='com.redhat.spice.0'/>
      <address type='virtio-serial' controller='0' bus='0' port='1'/>
    <input type='mouse' bus='ps2'/>
    <input type='keyboard' bus='ps2'/>
    <graphics type='spice' autoport='yes'>
      <listen type='address'/>
      <image compression='off'/>
    <sound model='ich6'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
      <model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1' primary='yes'/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='1'/>
    <redirdev bus='usb' type='spicevmc'>
      <address type='usb' bus='0' port='2'/>
    <memballoon model='virtio'>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>

Leave a Reply

Your email address will not be published.