10

For a test I need to allow routing from my local network to a guest inside a VirtualBox. The guest already have outside access.

So far I enabled ip forwarding on my local machine (OSX 10.9) and added a route to the host-only network on the machine on the local network.

route add -net 192.168.59.0 netmask 255.255.255.0 gw 192.168.0.107
sysctl -w net.ipv4.ip_forward=1

The network look like that.

Local network 192.168.0.104 -> [Wireless 192.168.0.0/24] -> MacOSX 192.168.0.107 (Wifi) & 192.168.59.3 (VboxHost) -> [VBox 192.168.59/24] -> 192.168.59.103

Unless VirtualBox is purposely dropping packet from the outside this should work.

My goal would be for 192.168.0.104 to connect to 192.168.59.103. So far I can only ping 192.168.59.3 from it.

Also, my guest already have another adapter with a default gw that allow access to the wifi.

What route or network config could I be missing?

Also I could understand the packet getting the my guest, but the guest not being able to reply, however tcpdump show no paquet ever get to guest if say I ping the machine. Also no firewall is running anywhere.

Routing table on my Mac

Destination        Gateway            Flags        Refs      Use   Netif Expire
default            192.168.0.1        UGSc           42        1     en0
127                127.0.0.1          UCS             0        0     lo0
127.0.0.1          127.0.0.1          UH              6  2943735     lo0
169.254            link#4             UCS             0        0     en0
192.168.0          link#4             UCS             3        0     en0
192.168.0.1        9c:d6:43:c8:cf:e8  UHLWIir        43    21647     en0   1199
192.168.0.104      8:0:27:c2:fc:68    UHLWI           0        7     en0   1068
192.168.0.106      0:15:99:77:73:ed   UHLWI           0       82     en0    845
192.168.0.107      127.0.0.1          UHS             2     9114     lo0
192.168.59         link#9             UC              3        0 vboxnet
192.168.59.3       a:0:27:0:0:0       UHLWI           0    69759     lo0
192.168.59.103     link#9             UHRLWIi         2    31866 vboxnet     1
7
  • 3
    Any reason you can't just configure your VM's network adapter to be bridged instead of host-only? Your effectively getting the same behavior.
    – heavyd
    Commented Jul 25, 2014 at 6:54
  • The same? The host only adapter is separate network, while bridged AFAIK will bind the host to my real network. Which inconvenient because IP while change from office, to home, etc.
    – kkx
    Commented Jul 25, 2014 at 14:47
  • I'm a VMware guy but like @heavyd mentioned, you should be able to setup a private or "host only" LAN with Virtual Box just like you can with VMware Fusion or Workstation.
    – SaxDaddy
    Commented Jul 26, 2014 at 2:46
  • @SaxDaddy It's exactly that I'm using but trying to route traffic to it for a test. However like I said not working like it should/want (or it's actually doing too good of a job). The host-only adapter seems to be dropping outside traffic, even if the routing is correct or something in MacOSX is no routing the traffic properly.
    – kkx
    Commented Jul 26, 2014 at 22:28
  • 4
    I am astounded that no one noticed the error in this configuration, since it is so obvious: in the route add command, the host-only network was configured to use as a gateway a pc outside the host-only network. This cannot possibly work. The correct route should have used as gw the IP address of the mac interface on the host-only adapter, not its default LAN. There are other mistakes (why does lo have an address of 192.168.59.3 in the routing table???) but with the error in route add no progress at all is possible. I leave this note for eventaul readers. Commented Apr 22, 2017 at 8:57

1 Answer 1

1

Host-only networking mode cannot be used to route traffic from the local network to the VM hosts. You should use use Bridged, NAT or NAT network. With the last two you need a port-forward.

References:

[1] https://www.virtualbox.org/manual/ch06.html#networkingmodes (See the table at the end of section 6.2) [2] https://www.virtualbox.org/manual/ch06.html#network_hostonly

2
  • Sorry that's not true. I think the documentation may be misleading. The host only network is like an independent LAN true, but LANs can have gateways and there is nothing to stop the host (or even one of the guests) acting as a router. I do it all the time on LInux I don't see why it shouldn't be possible on OS-X. Bridging and routing are two different things.
    – Rodney
    Commented May 19, 2019 at 13:38
  • Notice that we are using Virtualbox defined terms, not common sense. I was mislead by the words, that is why I pointed to the table at the documentation. Commented May 20, 2019 at 17:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .