This story describes how to use Open vSwitch to allow VMs on one hosts to communicate over port-based GRE tunnels. I want to use 192.168.42.1/24 IP range for these two VMs.
- To set up Open vSwitch (OVS) on both VMs and configure a simple distributed virtual switch based on a GRE tunnel, follow the steps below. This example assumes you are using Ubuntu as the Linux distribution. Adjust the package installation commands based on your distribution.
Step 1: Install Open vSwitch on Both VMs
# Update package list
sudo apt-get update
# Install Open vSwitch
sudo apt-get install openvswitch-switch
Step 2: Create an OVS bridge on two VMs:
sudo ovs-vsctl add-br br0
Step 3: Configure a Simple Distributed Virtual Switch with a GRE Tunnel
On VM1:
- Create a TAP device named
tap0
and set its type to internal:
sudo ip tuntap add tap0 mode tap
sudo ovs-vsctl add-port br0 tap0
sudo ovs-vsctl set interface tap0 type=internal
2. Assign an IP address to tap0
:
sudo ifconfig tap0 192.168.42.1 netmask 255.255.255.0
3. Create a GRE tunnel interface named gre0
:
sudo ovs-vsctl add-port br0 gre0 -- set interface gre0 type=gre options:remote_ip=<VM2_IP>Replace <VM2_IP> with the IP address of VM2.
#Replace <VM2_IP> with the IP address of VM2.
On VM2:
- Create a TAP device named
tap1
and set its type to internal:
sudo ip tuntap add tap0 mode tap
sudo ovs-vsctl add-port br0 tap1
sudo ovs-vsctl set interface tap1 type=internal
2. Assign an IP address to tap1
:
sudo ifconfig tap1 192.168.42.2 netmask 255.255.255.0
3. Create a GRE tunnel interface named gre0
:
sudo ovs-vsctl add-port br0 gre0 -- set interface gre0 type=gre options:remote_ip=<VM1_IP>
#Replace <VM1_IP> with the IP address of VM1.
Step 4: Verify the Configuration
- Check the OVS bridge configuration:
sudo ovs-vsctl show
#Ensure that both tap0 and tap1 and gre0 are listed under the Port section.
2. Verify the TAPs device configurations:
#VM1
ip addr show tap0
#VM2
ip addr show tap1
Step 5: Test Connectivity
- Ping from VM1 to VM2:
ping 192.168.42.2
2. Ping from VM2 to VM1:
ping 192.168.42.1
Step 6: Cleanup
To remove the configurations and cleanup:
# On VM1
sudo ovs-vsctl del-port br0 tap0
sudo ovs-vsctl del-port br0 gre0
sudo ip link delete tap0
sudo ovs-vsctl del-br br0
# On VM2
sudo ovs-vsctl del-port br0 tap1
sudo ovs-vsctl del-port br0 gre0
sudo ip link delete tap1
sudo ovs-vsctl del-br br0
These steps will remove the configurations and undo the changes made during the setup. Adjust the commands if you are using a different Linux distribution.