The same network segment between the VMs of multiple hosts in vxlan

Three machines
establish a namespace, and vxlan connects to each other. The vms
created by the three machines are connected to the namespace and
communicate with the vms of other machines,

so that
the three vms of the three machines look like the script qemu_br


executed when qemu starts on the same network segment
.sh:
###############
#
!/bin/sh
ip netns add zou

ip link add zouveth0 type veth peer name zouveth1
ip link set zouveth1 netns zou

brctl addbr br-zou
brctl addif br-zou zouveth0
#Here 192.168.139.251 is replaced with the ip of the local machine, and eth0 is replaced with the network card with the ip of the local machine
ip link add vxlan-10 type vxlan id 10 group 239.1.1.1 local 192.168.139.251 dev eth0
brctl addif br-zou vxlan-10

ip link set dev zouveth0 up  
ip netns exec zou ip link set dev zouveth1 up  
ip netns exec zou ip link set dev lo up  
ip link set dev br-zou up  
ip link set dev vxlan-10 up

ip netns exec zou brctl addbr br0
ip netns exec zou ip link set br0 up  
ip link set tap1 netns zou
ip netns exec zou ip link set tap1 up  
ip netns exec zou brctl addif br0 tap1
#Here 10.1.0.5/24 Replace the ip of the namespace that you want to set on this machine
ip netns exec zou ip addr add 10.1.0.5/24 dev br0
ip netns exec zou brctl addif br0 zouveth1

##############

Delete script delbr0.sh:
############
#!/bin/sh
ip link set br-zou down
ip link del br-zou
ip link del vxlan-10
ip netns del would

##############


start vm
###################
/usr/libexec/qemu-kvm -kernel bzImage -drive file=hda.img,if=ide,cache=none -append "console=ttyS0 root=/dev/sda rw rdinit=/sbin/init notsc=1"  -nog
raphic -boot order=dc,menu=on -net nic,vlan=0,macaddr=52:54:00:12:34:21,model=e1000,addr=08 -net tap,name=haha,ifname=tap1,script=qemu_br.sh,downscr
ipt=delbr0.sh

################

View the set namespace
ip netns
ip netns exec zou ip addr
ip netns exec zou brctl show
ip netns exec zou ifconfig


In the started vm:
set the ip and gateway for the vm
##############
#!/bin/sh
#Replace the ip of the vm you want to set on the local machine
ip addr add 10.1.0.11/ 24 dev eth0
ip link set eth0 up
ip route add default via 10.1.0.5
################



After multiple machines are set up,
such as
192.168.139.251---->namespace:10.1. 0.5--->vm:10.1.0.11
192.168.139.252---->namespace:10.1.0.6--->vm:10.1.0.12
192.168.139.253---->namespace:10.1.0.7--->vm :10.1.0.13

goes from 10.1.0.11 ping 10.1.0.12
to:
on 192.168.139.251:
vm:10.1.0.11--->tap1--->br0:10.1.0.5--->zouveth1--->namespace --->zouveth0-->br-zou-->vxlan-10-->eth0
on 192.168.139.252:
vm: 10.1.0.12 <--- tap1 <--- br0: 10.1.0.6 <--- zouveth1 <--- namespace <--- zouveth0 <- br-zou <- vxlan-10 <- eth0













Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326450059&siteId=291194637