Skip to content

Instantly share code, notes, and snippets.

@khenidak
Created July 17, 2018 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save khenidak/f94924c6f00e401b643d4e5f7402cba5 to your computer and use it in GitHub Desktop.
Save khenidak/f94924c6f00e401b643d4e5f7402cba5 to your computer and use it in GitHub Desktop.
vxlan.0
#!/bin/bash
# What is this: it creates vxlan across two hosts
# does this need multicast on hosts: no, we are using the no learning approach
# How: we are using static popluation of fdb and arp database. (we don't use l2miss or l3miss - maybe we try it on a different script)
# What do i need:
# two VMs running everywhere, as long as you can do udp between them.
# modify host1/2 for host ips (your VMs)
# modify ip1/ip2 and vip1/vip2 for your configuration.
# the script connect to VMs via ssh. so make sure you have the keys handy
# what can i use it for: VMs/Containers/funky networking. get creative
set -e
host1=192.168.124.89
host2=192.168.124.90
mac1="$(echo 00:60:2f$(od -txC -An -N3 /dev/random|tr \ :))"
mac2="$(echo 00:60:2f$(od -txC -An -N3 /dev/random|tr \ :))"
ip1="11.0.0.4/24"
ip2="11.0.0.5/24"
vip1="11.0.0.4"
vip2="11.0.0.5"
echo "* mac1: ${mac1} mac2:${mac2}"
echo "* create vtep"
ssh "${host1}" "sudo ip link add vxlan100 type vxlan id 100 dstport 4789 local 192.168.124.89 nolearning proxy"
ssh "${host2}" "sudo ip link add vxlan100 type vxlan id 100 dstport 4789 local 192.168.124.90 nolearning proxy"
echo "* create veth"
ssh "${host1}" "sudo ip link add name nic0 type veth peer name vnic0 address ${mac1}"
ssh "${host2}" "sudo ip link add name nic0 type veth peer name vnic0 address ${mac2}"
echo "* add bridge + ifs"
ssh "${host1}" "sudo brctl addbr br100 && sudo brctl addif br100 vxlan100 && sudo brctl addif br100 nic0"
ssh "${host2}" "sudo brctl addbr br100 && sudo brctl addif br100 vxlan100 && sudo brctl addif br100 nic0"
echo "* switch off bridge stp"
ssh "${host1}" "sudo brctl stp br100 off"
ssh "${host2}" "sudo brctl stp br100 off"
echo "* assing ips"
ssh "${host1}" "sudo ip addr add ${ip1} dev vnic0"
ssh "${host2}" "sudo ip addr add ${ip2} dev vnic0"
echo "* bring interfaces up"
ssh "${host1}" "sudo ip link set up dev nic0"
ssh "${host1}" "sudo ip link set up dev vxlan100"
ssh "${host1}" "sudo ip link set up dev br100"
ssh "${host1}" "sudo ip link set up dev vnic0"
ssh "${host2}" "sudo ip link set up dev nic0"
ssh "${host2}" "sudo ip link set up dev vxlan100"
ssh "${host2}" "sudo ip link set up dev br100"
ssh "${host2}" "sudo ip link set up dev vnic0"
echo "* fill fdb addresses + arp entries"
ssh "${host1}" "sudo bridge fdb append ${mac2} dev vxlan100 dst ${host2}"
ssh "${host2}" "sudo bridge fdb append ${mac1} dev vxlan100 dst ${host1}"
ssh "${host1}" "sudo ip neigh add ${vip2} lladdr ${mac2} dev vxlan100"
ssh "${host2}" "sudo ip neigh add ${vip1} lladdr ${mac1} dev vxlan100"
echo "* are you there?"
ssh "${host1}" "ping -c5 ${vip2}"
ssh "${host2}" "ping -c5 ${vip1}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment