Setup vxlan Network with L2 Connectivity between VMs

Cat Administrator

This tutorial show you how to create vxlan Network with L2 Connectivity between VMs (Compute Engine) in google cloud
Create VPC Network named vxlan-network
with custom mode
1gcloud compute networks create vxlan-network \2 --project=trial-project-andania \3 --subnet-mode=custom
Create Subnet on vxlan-network
VPC Network
1gcloud compute networks subnets create us-central1-subnet \2 --project=trial-project-andania \3 --range=10.40.0.0/20 \4 --network=vxlan-network \5 --region=us-central1
Create firewall rules to allow SSH and icmp for the VMs
1gcloud compute firewall-rules create vxlan-network-allow-ssh-icmp \2 --project=trial-project-andania \3 --network vxlan-network \4 --allow tcp:22,icmp
Create two VM instances named vm-a
and vm-b
. (I use spot vm for this example to reduce the cost)
1gcloud compute instances create vm-a \2 --project=trial-project-andania \3 --image-family=ubuntu-2004-lts --image-project=ubuntu-os-cloud \4 --zone=us-central1-a \5 --boot-disk-size 10G \6 --machine-type=e2-medium \7 --can-ip-forward \8 --network=vxlan-network \9 --subnet=us-central1-subnet \10 --scopes cloud-platform \11 --provisioning-model=SPOT12
13gcloud compute instances create vm-b \14 --project=trial-project-andania \15 --image-family=ubuntu-2004-lts --image-project=ubuntu-os-cloud \16 --zone=us-central1-a \17 --boot-disk-size 10G \18 --machine-type=e2-medium \19 --can-ip-forward \20 --network=vxlan-network \21 --subnet=us-central1-subnet \22 --scopes cloud-platform \23 --provisioning-model=SPOT
Setup vxlan on both VMs
-
SSH to vm-a as root user and setup vxlan
Terminal window 1gcloud compute ssh root@vm-a --zone us-central1-a2ip link add vxlan0 type vxlan id 42 dev ens4 dstport 03bridge fdb append to 00:00:00:00:00:00 dst $VM_B_IP dev vxlan04ip addr add 10.200.0.2/24 dev vxlan05ip link set up dev vxlan0 -
SSH to vm-b as root user and setup vxlan
Terminal window 1ip link add vxlan0 type vxlan id 42 dev ens4 dstport 02bridge fdb append to 00:00:00:00:00:00 dst 10.40.0.2 dev vxlan03ip addr add 10.200.0.3/24 dev vxlan04ip link set up dev vxlan0Test ping from vm-a to vm-b and vice versa. You will get an error
Destination Host Unreachable
. This is because we still not open port to allow connectivity on vxlan.
Add firewall rules to open Overlay Transport Virtualization (OTV) and Virtual eXtensible Local Area Network (VXLAN) UDP ports
1gcloud compute firewall-rules create vxlan-network-allow-vxlan-udp \2 --project=trial-project-andania \3 --network=vxlan-network \4 --allow udp:4789,udp:8472
Now test ping again from vm-a to vm-b and vice versa. The ping will now success.