jedi4ever / veewee

Easing the building of vagrant boxes
MIT License
4.29k stars 779 forks source link

Multiple NICs on virtualbox #1040

Open nettucu opened 9 years ago

nettucu commented 9 years ago

Hi,

I wanted to be able to build a virtualbox vm and have 4 NICs attached to it. It turned out you can not by default do that because of the way VBox assigns IPs to NAT. If the NIC to get NAT is eth0 all is well and it works, but if it's eth3 it doesn't work anymore because veewee serves the kickstart on the wrong IP. I managed to get it working by changing lib/veewee/provider/virtualbox/box/helper/ip.rb:

diff --git i/lib/veewee/provider/virtualbox/box/helper/ip.rb w/lib/veewee/provider/virtualbox/box/helper/ip.rb
index 3791a8b..fef85ec 100644
--- i/lib/veewee/provider/virtualbox/box/helper/ip.rb
+++ w/lib/veewee/provider/virtualbox/box/helper/ip.rb
@@ -5,7 +5,12 @@ module Veewee

         # http://www.virtualbox.org/manual/ch09.html#idp13716288
         def host_ip_as_seen_by_guest
-          "10.0.2.2"
+          # as per definition in virtualbox 
+          # we need to add 1 because vboxmanage starts counting from 1 for display,
+          # but counts from 0 when actually assigning the IP
+          host_ip = "10.0.#{self.natinterface.to_i + 1}.2"
+          return host_ip # "10.0.2.2"
+          #"10.0.2.2"
         end

The idea is that VBox has a bad habbit of counting eth0, eth1, eth2 when it assigns the IP address from 10.0.x.2 and the webserver is launched on the wrong ip

mpapis commented 9 years ago

please open a pull request with this change, did you had chance to test it in more configurations?