Mininet

Docker

Namespace

  • This note will show you how to build a mininet-like virtual network through an example.
  • Source Code

KVM

  1. Install dependencies

    sudo apt-get install qemu-kvm libvirt-bin virt-manager bridge-utils
    sudo apt-get install ubuntu-vm-builder
    sudo apt-get install virtinst
    
  2. Create a VM

    virt-install --name vm1 --hvm --ram 2048 --vcpus 2 --disk path=/home/yche/kvm/image/vm1.img,size=30  --network network:default --accelerate  --vnc --cdrom /home/yche/kvm/iso/ubuntu-16.04.5-server-amd64.iso -d
    
  3. Access network by OVS

    • Modify the testVM.xml(/etc/libvirt/qemu/testVM.xml) as follows.

      ...
      </controller>
      <interface type='bridge'>
      <source bridge='test’'/>
      <virtualport type='openvswitch'>
      </virtualport>
      <model type='virtio'/>
      </interface>
      <serial type='pty'>
      ...
      
    • Add a bridge and configure iptables

      ovs-vsctl add-br test
      sudo ifconfig test 192.168.0.1/24 up
      # NAT
      echo 1 > /proc/sys/net/ipv4/ip_forward
      iptables -t nat -A POSTROUTING -s 192.168.0.0/24 ! -d 192.168.0.0/24 -j MASQUERADE
      
    • Configure DNS and gateway

      virsh start testVM (A new network interface eth0 has been created)
      
      #edit /etc/network/interface 
      auto lo
      iface lo inet loopback
      auto eth0
      iface eth0 inet static
      address 192.168.0.2
      netmask 255.255.255.0
      network 192.168.0.0
      broadcast 192.168.0.255
      gateway 192.168.0.1
      dns-nameservers 8.8.8.8
      #auto eth1
      #iface eth1 inet static
      #address 10.0.0.10
      #netmask 255.255.255.0
      #network 10.0.0.0
      #broadcast 10.0.0.255
      
    • Reboot

      sudo apt-get install openssh-server  (in testVM, maybe need to run ‘sudo apt-get update first