VirtualBox访问外网,并能从主机访问的设置

来源:互联网 发布:adobe软件 mac百度云 编辑:程序博客网 时间:2024/05/15 04:07

https://geert.vanderkelen.org/2011/virtualbox-give-host-only-access-to-internet/

这个配置貌似是可用的:



VirtualBox: give Host-Only access to internet

This post describes a simple trick for VirtualBox to give host-only virtual machines access the internet or access your host from the guest using NAT.

Problem

The original problem or requirements were as follows:

  • The host should be able to browser the webserver on the Guest (the virtual machine)
  • The guest should be able to access the outside world (intranet/internet)
  • Use fixed IP address

Yes, you can use port-forwarding using NAT network interface for the virtual machine. But configuring this is just way to complicate and error prone. A few googles more, and I couldn’t find anything good.

Solution

The solution I came up with: configure 2 network interfaces for your Virtual Box host. Simple, isn’t it?

First, we need to make a new network in VirtualBox. You can do this in the GUI preference, which is a bit platform specific, but it’s not easy to miss.

Create a new network in VirtualBox, named like vboxnet2 with following settings (change to suit your needs):

  • IPv4 Address: 10.88.12.0
  • IPv4 Network Mask: 255.0.0.0
  • Leave DHCP disabled if you don’t need it. Fixed IP addresses are just more predictable

Setup your virtual machine using 2 network adapters. The order doesn’t really matter, but you’ll need one NAT and one Host-Only:

  1. NAT (not much to configure).
  2. Host-Only using the network you created earlier, for example, vboxnet2.

Boot your virtual machine, and configure the network interfaces in your guest OS (same order as previous point):

  1. First interface using NAT, which you can use with the internal DHCP
  2. Second interface using Host-Only will use a fixed IP address and netmask which you configured earlier for the vboxnet2 VirtualBox network. For example, 10.88.12.4.

Guest has access to outside, and host can access services running on guest. This is handy when you have a demo or develop using a service running in the virtual machine, and the virtual machine needs to access the outside world.

(If the above has been posted somewhere else: I was either blind, or it was not visible or indexed enough.)


0 0