How to enable routing in OS X El Capitan

I've got a Linux VMware virtual machine (guest) configured with a NAT adapter on a 192.168.56.0 subnet. Its IP address is 192.168.56.128 and my Mac (host) got 192.168.56.1. Guest's default gateway is automatically set to 192.168.56.2 and is able to ping google from the guest. Host's Wi-Fi IP is 192.168.0.2,

I've configured my Wi-Fi router with following routing table to forward packets of 192.168.56.0 to 192.168.0.2 (my Mac)

pi@raspberrypi ~ $ route

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         172.16.4.1      0.0.0.0         UG    0      0        0 eth0
172.16.4.0      *               255.255.252.0   U     0      0        0 eth0
192.168.0.0     *               255.255.255.0   U     0      0        0 wlan0
192.168.56.0    192.168.0.2     255.255.255.255 UGH   0      0        0 wlan0
192.168.57.0    192.168.0.2     255.255.255.255 UGH   0      0        0 wlan0

But I'm unable to ping guest from any other device on the Wi-Fi network (192.168.0.0). So it's obvious that my Mac running OS X El Capitan is not forwarding the packets from 192.168.0.0 to 192.168.56.0


Your router is not responsible to route packets from 192.168.0.0 to 192.168.56.0, but the VM host is. You have to keep the static route 192.168.56.0 -> 192.168.0.2 on the router though. I don't know what's the purpose of the second route 192.168.57.0 -> 192.168.0.2 - probably a second NAT adapter on the host.

To reach your VM from other OS X devices in your 192.168.0.0 network you have to set up a static route on each of the 192.168.0.x machines to the VM host:

sudo route add -net 192.168.56.0  192.168.0.2

To make this route persistent add a launch daemon on each of the machines:

sudo nano /Library/LaunchDaemons/local.staticroute.vm.plist

with the content

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>local.staticroute.vm</string>
    <key>ProgramArguments</key>
    <array>
      <string>route</string>
      <string>add</string>
      <string>-net</string>
      <string>192.168.56.0</string>
      <string>192.168.0.2</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
  </dict>
</plist>

save the file (ctrl-O) and quit nano (ctrl-X).

Load the launch daemon with:

sudo launchctl load -w /Library/LaunchDaemons/local.staticroute.vm.plist

If the other devices in the 192.168.0.0 network are Linux/Windows/Android hosts use the respective commands to add a route:

Windows (persistent):

route add -p 192.168.56.0 mask 255.255.255.0 192.168.0.2 

Linux:

route add -net 192.168.56.0 netmask 255.255.255.0 gw 192.168.0.2

To add a persistent route in Linux check your Linux distro documentation.