12

I'm using Open vSwitch to create a switched network between virtualBox guest machines, and i want that the host OS (Ubuntu 12.04) join this network and to configure it as the gateway of this virtual network:

First, i created a vswitch and i added ports to tap devices (that virtual machines use them as bridged interfaces):

ovs-vsctl add-br sw0
ovs-vsctl add-port sw0 tap0

After that, i set statically the ip of Lubuntu 12.04 virtual machine :

ifconfig eth0 192.168.1.3/24 up
route add -net 0.0.0.0/0 gw 192.168.1.1

In the host os side, i also set the ip address :

ifconfig sw0 192.168.1.1/24 up

At this time, i can ping from Lubunut to Ubunutu. I want now, in the host machine to use IP masquerade to forward traffic from network 192.168.1.0/24 to my physical interace (connected to Internet) :

sysctl -w net.ipv4.ip_forward=1
iptables -t nat -A POSTROUTING -o eth1 -s 192.168.1.0/24 -j MASQUERADE

So from Lubuntu (the virtual machine), i can ping the Ubuntu eth1 interface, but i cannot reach the real network (e.g: the gateway on real LAN), i have tried :

nslookup google.com
dig @8.8.8.8 yahoo.com
dig @192.168.30.1 google.com

Network Topology

   Internet (real gw) ------ Host OS -------- vswitch -------- VBox Guest 1
           192.168.30.1   ip masquerade    192.168.1.0/24
                                                |
                                                 ------------ VBox Guest 2
LokmanDz
  • 121
  • 1
  • 1
  • 5

2 Answers2

1

The answer is not really mine, but... Try following Open vSwitch on VirtualBox

There was also a brief text file from some Fedora people on similar subject: libvirt and OpenVSwitch in a form of text file... wasn't able to locate it though.

as per comment, here's short summary:

(1) Create vnet0 interface and br0 bridge:

ovs-vsctl add-br br0
ip tuntap add mode tap vnet0
ip link set vnet0 up
ovs-vsctl add-port br0 vnet0
ip link # (View the created interface)

(2) spin up VM that uses vnet0 interface (as a bridged adapter)

(3) connect bridge br0 to real network:

ovs-vsctl add-br br0 
ovs-vsctl add-port br0 eth0 
ovs-vsctl add-port br0 vnet0 
ifconfig eth0  0 && ifconfig br0 192.168.1.(X) netmask 255.255.255.0
route add default gw 192.168.1.1 br0
route del default gw 192.168.1.1 eth0
Droopy4096
  • 670
  • 3
  • 7
  • Since you are linking to an external article which may change, it is recommendable to summarize the solution in your answer and reference the article instead. – Esa Jokinen Apr 06 '15 at 06:57
0

Enable forwarding upon reboot by un-commenting these lines in /etc/sysctl.conf:

net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=1
Shōgun8
  • 194
  • 1
  • 10