#!/bin/bash

# Stop dhcp
sudo killall dhclient

# Create switch
sudo ovs-vsctl add-br br0
sudo ovs-vsctl add-port br0 eth0 

# Save current MAC addresses
ETH0_MAC=`ip link show eth0 | awk 'NR==2 { print $2 }'`
BR0_MAC=`ip link show br0 | awk 'NR==2 { print $2 }'`

# Save ip address
ETH0_IP=`ip a show eth0 | grep "inet " | awk '{print $2}'`

# Spoof MAC of eth0 on br0
sudo ip link set dev eth0 address $BR0_MAC
sudo ip link set dev br0 address $ETH0_MAC

# Remove ip from eth0 and add it to br0 
sudo ip addr del $ETH0_IP dev eth0 
sudo ip addr add $ETH0_IP dev br0

# Make sure interfaces are up
sudo ip link set eth0 up
sudo ip link set br0 up

# Start dhcp on new interface
sudo dhclient br0 

