I have a Mac (hermione, IP that runs a Virtualbox VM with address netstat -rn on that machine says:

192.168.97         link#23            UC              2        0 vboxnet      !       a:0:27:0:0:2       UHLWI           0        4     lo0     8:0:27:f0:e0:3e    UHLWIi          1        2 vboxnet    961

When I'm on that Mac, everything is fine, I can ping (VirtuaBbox itself) and (the VM).

Now, I want to be able to reach these from the outside. So on another Mac (luna) I've tried setting up routes to do that, e.g.

sudo route -v -t add -net 192.168.97


sudo route -v add -host

Telling luna to route traffic for to (the IP address of hermione).

But traffic won't get through. Is macOS capable of this at all and if so, what am I doing wrong?

  • 3
    Why not just st use a bridged adapter on your VM? – Allan Jan 30 '19 at 17:23
  • Because the Virtualbox VM is running Docker and Docker containers. – gctwnl Jan 30 '19 at 19:47
  • 1
    Then you have to do NAT port forwarding – Allan Jan 30 '19 at 20:16
  • And then the question is: how? I'm assuming that since it works on the machine where the VM runs, I have to do something on the Mac to get outside requests passed on and I have to do something on the other Macs to get traffic routed to that Mac – gctwnl Feb 1 '19 at 13:49

You have to set up NAT port forwarding rules then access your services by using the IP address of your Mac much like you would if it were a host behind a traditional firewall/router.

You can do this via the VirtualBox GUI in the Port Forwarding rules setup in the Network Settings preference pane for the individual VM. In the example below, I show how you can set port forwarding for SSH on port 2222 of your host to port 22 of your guest (using the IPs from your question).

enter image description here

enter image description here

Alternatively, you can do this via the CLI using VBoxManage modifyvm. So using the same example as above:

$ VBoxManage modifyvm "VM NAME" --natpf1 "SSH,tcp,,2222,,22"

You must log in to answer this question.

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