3

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

2

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.

  • 1
    what is this xml? This is the sickest use of XML i've ever come across! – Necktwi Feb 3 '16 at 18:48
  • This is to reach from other Macs on the network 192.168.0.0 – Necktwi Feb 4 '16 at 4:19
  • I'm unable to reach my VM even from my router! – Necktwi Feb 4 '16 at 4:20
  • Yes my VM host is responsible for routing packets from 192.168.0.0 to 192.168.56.0. So how to make the host(Mac) to do that? – Necktwi Feb 5 '16 at 6:37
  • @neckTwi Please implement my solution. Report back if you still have trouble. I tested it in a similar environment as yours and it works. Please change the default gateway on the Linux VM to 192.168.56.1 (because this is the host's=gateway internal address). – klanomath Feb 5 '16 at 12:54
0

This didn't survive reboot for me in 10.11. I followed these instructions:

sudo networksetup -setadditionalroutes Wi-Fi 192.168.56.0 255.255.255.0 192.168.0.2

where Wi-Fi is found using networksetup -listallnetworkservices.

You must log in to answer this question.

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