1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Can you allow the host to use the VM network connection?

Discussion in 'Linux / BSD / Mac OS X' started by MatteusBlanc, Mar 23, 2011.

  1. MatteusBlanc New Member

    Mar 23, 2011
    1 (0.00/day)
    Thanks Received:
    If you use a VM...

    this is possible although not immediately obviously useful. My situation was one where the vm os was able to change settings on a wireless network adapter which allowed me to pick up the signal at a useable strength. The host could not do this. So I was in the weird situation where the vm os - backtrack - had internet but the host - osx 10.6 - did not. Annoying.

    Easily corrected as follows:
    1. connect the vm to the network, in my case this was wireless so wlan0
    2. set up the vm so that is has a local network with the host, make sure the host can ping the vm. In my case this meant enabling eth0 in the vm
    3. set up ip forward and iptables masquerade rules on the vm.
    4. change the default route of the host to be the vm local ip
    5. enjoy the vm network via the host

    now I imagine some readers will want more detail on ip forward and masquerade with iptables but there are a lot of tutorials out there for this stuff. It depends on the vm os but if you are using linux then

    ip forward with:
    $ echo 1 > /proc/sys/net/ipv4/ip_forward

    iptables rules something like this
    iptables -t nat -A POSTROUTING -s $PRIVATE -o eth0 -j MASQUERADE

    {clearly $PRIVATE is your private subnet, set the rules up to run at ifup}

    Last edited: Mar 23, 2011
  2. Easy Rhino

    Easy Rhino Linux Advocate

    Nov 13, 2006
    14,377 (3.66/day)
    Thanks Received:
    that is pretty damn clever.
    10 Year Member at TPU

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)