Route traffic from local network to VirtualBox host-only adapter
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
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