0

I have a mac book running Mac OS High Sierra. It is host to three virtual machines running Ubuntu 16.04. All VMs have two adapters enabled; NAT and Host-Only. The mac is connected to another host via a switch. The VMs co-ordinate and provide a service which I would like to be available to the host at the other end of the switch connected to my laptop.

                                     en8                                         
 192.168.57.0     192.168.57.200     192.168.57.100   /---|VM1| 192.168.56.3
|------------|   /--------------\   |--------------| /
|   Host1    |--|     switch     |--|    Host2     |------|VM2| 192.168.56.4
|------------|   \--------------/   |--------------| \
                                     192.168.56.1     \---|VM3| 192.168.56.5
                                     vboxnet0

The hosts are on subnet 192.168.57.0\24. The laptop is connected to the switch through interface en8 with an IP address of 192.168.57.100. The laptop and the switch can ping each other.

Mac OS is connected to the VMs through gateway 192.168.56.1 on interface vboxnet0. The VMs can ping eachother and their host. The host can communicate with each VM.

I want the VMs to be able to control the switch, and so I need to set up a routing rule to connect traffic from the swtich to the VMs and back. I want to use my mac like a router to do this.

I tried following Jeff Warren's example here: Virtualbox: Connecting Host-Only networks on separate hosts, but it isn't working in my case.

Specifically, i tried...

sudo route -n add -net 192.168.56.0/24  192.168.57.100

but this didn't work. I got a message saying File already exists.

Any ideas on how I can make it possible to configure my switch from the VMs are much appreciated. Thank you.

I have tried other approaches, like putting the VMs on the same logical subnet as the switches. When I did this however, I lost communication between the VMs and their host. I also have tried using bridged network instead of host only, but this hasn't worked either.

1 Answer 1

1

Assuming that the 192.168.56.0/24 interfaces on the VMs are the host-only (i.e. not NAT).

You don't need routes on your MAC (host2) because that's the only one with direct attach to both /24. You do need your VMs to go this way to reach the switch, and the switch to go also this way to go to the VMs.

On the VMs, "ip route add 192.168.57.0/24 via 192.168.56.1" should do the trick.

On the switch... whatever syntax is needed, possibly to make the host2 it's default gateway (@192.168.57.100)

7
  • Thank you, I added the ip route rule on my VM, but I'm getting a destination unreachable when i ping 192.168.57.100. I tried modifying the rule to route to .57 via 192.168.56.1 thinking my VMs can reach the host through that address, but when I do this I get RTNETLINK answers: Network is unreachable. I did change the switch's gateway to 192.168.57.100 though.
    – Matt Hall
    Commented Mar 8, 2018 at 22:16
  • Sorry, yes, my typo. It should have been "via 192.168.56.1". What does an "ip route ls" show on the VMs ? Commented Mar 8, 2018 at 22:33
  • Your MAC (host2) also needs to be willing to forward traffic (i.e. route). It may be just enough to "echo 1 > /proc/sys/net/ipv4/ip_forward" or may need firewall rules tweeking if you have them. Commented Mar 8, 2018 at 22:37
  • i deleted the bad rule, ip route ls is now... default via 10.0.3.2 dev enp0s8 proto static metric 100 NEWLINE 10.0.3.0/24 dev enp0s8 proto kernel scope link src 10.0.3.15 metric 100 NEWLINE 169.254.0.0/16 dev enp0s8 scope link metric 1000 NEWLINE 192.168.57.0/24 dev enp0s3 proto kernel scope link src 192.168.57.3 metric 100 I tried to clean the formatting a bit for the comments but i'm not sure it helped so much
    – Matt Hall
    Commented Mar 8, 2018 at 22:41
  • Forwarding was enabled on the mac with sysctl -w net.inet.ip.forwarding=1
    – Matt Hall
    Commented Mar 8, 2018 at 22:50

You must log in to answer this question.

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