`
yangzb
  • 浏览: 3514237 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

VirtualBox网络配置(NAT和Host Interface)

阅读更多

VirtualBox提供了三种联网方式,在这里介绍前两种方式(NAT和HostInterface)的配置方法,第三种联网方式属于利用主机上的所有的虚拟机构建一个虚拟网络的方法,较简单,有兴趣的可以查看自带的用户手册。

第一种方式NAT:NAT(网络地址转换),你可以认为你的虚拟机是在你的主机后方,所有的联网请求都先通过主机(其实是通过主机的NAT服务器,这是VirtualBox内置的)。

  • 优点:配置简单,可以说只要你的主机可以上网那么配置就没有什么难的。
  • 缺点:虚拟OS的网络地址外网不可见,无法与你的主机进行通信,所以如果你要利用主机和你的虚拟OS调试网络应用程序,恐怕不能使用这种联网方式。

配置步骤:

第一步:打开VirtualBox的设置窗口

第二步:进入网络设置界面,并将Attached To 选项选为NAT,点击确定

第三步:启动虚拟操作系统,并在该系统中设置联网方式为DHCP(***重要),自动获得网络地址,VirtualBox会使用10.0.0.0这样的地址进行联网。这样你的虚拟OS上网,收发邮件都没有问题。但是无法和主机网络中的其他PC通信哦。

 

下面介绍Host Interface的方式进行连接

先关闭你的虚拟操作系统^_^

第一步:打开设置界面,到网络选项卡下,并选择Host Interface连接方式,其他设置不需要改变

 

第二步:在网络选项卡下方的Host Interfaces中,新建一个网络接口,点击右方的绿色button。这样会在你的主机的网络连接中增加一个VirtualBox Host Interface 1这样的一个本地连接。

在主机的网络连接中,新建的连接是默认断开的(当然咯,因为你的虚拟主机还没有启动嘛)

第三步:很重要的一步,我就是卡在这里好久时间才搞明白。VirtualBox需要设置一个网桥,而使得所虚拟出来的网络接口可以通过你本机的网卡进行联网。怎么设置呢?

选中上图中的两个本地连接,右键,选择桥接就可以咯。

第四步:进入虚拟操作系统,修改联网方式为静态IP的方式,这样就OK了

 

分享到:
评论
1 楼 yangzb 2009-09-15  
VirtualBox NAT设置和端口转发

这是我对 VirtualBox 自带帮助关于 NAT 设置部分的翻译,翻的不当处,请批评指正,我不是英语专业。未完,待续。转载我的文章,请注明出处,非常感谢。

1、  Network Address Translation (NAT)

Network Address Translation (NAT) is the simplest way of accessing an external network from a virtual machine. Usually, it does not require any configuration on the host network and guest system. For this reason, it is the default networking mode in VirtualBox.

网络地址转换( NAT )是最简单的方法从一个虚拟机访问外部网。通常,它并不要求在主机网络和客户机上做任何配置。基于这个原因,它是默认的网络模式 。

A virtual machine with NAT enabled acts much like a real computer that connects to the Internet through a router. The “router”, in this case, is the VirtualBox networking engine, which maps traffic from and to the virtual machine transparently. The disadvantage of NAT mode is that, much like a private network behind a router, the virtual machine is invisible and unreachable from the outside internet; you cannot run a server this way unless you set up port forwarding (described below).

设置为通过 NAT 方式连接的一台虚拟机能像一台真正的计算机一样访问互联网,主机就是一只路由器。 在这种方式下,通过 VirtualBox 网络引擎,虚拟机透明地映射到外部网络。 NAT 方式不方便是,很像是在路由器之后的一个专用网络,从外部互联网看来,虚拟机是无形和不能到达的; 您不可能在虚拟机上运行一个服务器,因为外部网络无法访问通过 NAT 方式连接的内部机,除非您设定了端口转发(下述)。

The virtual machine receives its network address and configuration on the private network from a DHCP server that is integrated into VirtualBox. The address which the virtual machine receives is usually on a completely different network to the host.As more than one card of a virtual machine can be set up to use NAT, the first card is connected to the private network 10.0.2.0, the second card to the network 10.0.3.0 and so on.

虚拟机从一个 VirtualBox 整合的 DHCP 服务器得到私有的网址。这个网址对主机来说是一个完全不同的网络。一台虚拟机的多个网卡可以被设定使用 NAT, 第一个网卡连接了到专用网 10.0.2.0,第二个网卡连接到专用网络 10.0.3.0,等等。默认得到的客户端ip(IP Address)是10.0.2.15,网关(Gateway)是10.0.2.2,域名服务器(DNS)是10.0.2.3,可以手动参考这个进行修改。

The network frames sent out by the guest operating system are received by VirtualBox’s NAT engine, which extracts the TCP/IP data, and resends it using the host operating system. To an application on the host, or to another computer on the same network as the host, it looks like the data was sent by the VirtualBox application on the host, using an IP address belonging to the host. VirtualBox listens for replies to the packages sent, and repacks and resends them to the guest machine on its private network.

客户机(即虚拟机)送出的网络帧被 VirtualBox 的 NAT 引擎收到,抽取 TCP/IP 数据,再通过主机的操作系统(即安装 VirtualBox 的操作系统)重新发送出去。送到在主机上的一个应用程序,或者到位于主机同一网络的另一台计算机上,它看起来好象是安装在主机上的程序 VirtualBox,通过一个属于主机的 IP 地址,把数据发送出去。VirtualBox  倾听到数据包裹的回复,通过客户机的私人网络重新包装和发送往客户机上。

You can set up a guest service which you wish to proxy using the command line tool VBoxManage. You will need to know which ports on the guest the service uses and to decide which ports to use on the host (often but not always you will want to se the same ports on the guest and on the host). You can use any ports on the host which are not already in use by a service. An example of how to set up incoming NAT connections to a ssh server on the guest requires the following three commands:

你可以设置一个虚拟机的服务(比如 WEB  服务),通过使用命令行工具 VboxManage 代理。你需要知道虚拟机的服务使用哪个端口,然后决定在主机上使用哪个端口(通常但不总是想要使虚拟机和主机使用同一个端口)。在主机上提供一个服务需要使用一个端口,你能使用在主机上没有准备用来提供服务的任何端口。一个怎样设置新的 NAT 例子,在虚拟机上连接到一个 ssh 服务器,需要下面的三个命令:

VBoxManage setextradata "Linux Guest" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/Protocol" TCP

VBoxManage setextradata "Linux Guest" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/GuestPort" 22

VBoxManage setextradata "Linux Guest" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort" 2222

说明:VboxManage 是一个命令行程序,请查询你的 VirtualBox 安装目录,"Linux Guest" 是虚拟主机名。guestssh 是一个自定义的名称,你可以任意设置,通过上面的三个命令,把虚拟机的 22 端口 转发到主机的 2222 端口。

又比如,我在虚拟机 debian 上安装了 apache2 服务器,使用 80 端口,映射到主机的 80 端口。使用下面的命令。

"C:\Program Files\innotek VirtualBox\VBoxManage.exe" setextradata "debian" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/huzhangsheng/Protocol" TCP

"C:\Program Files\innotek VirtualBox\VBoxManage.exe" setextradata "debian" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/huzhangsheng/GuestPort" 80

"C:\Program Files\innotek VirtualBox\VBoxManage.exe" setextradata "debian" "VBoxInternal/Devices/pcnet/0/LUN#0/Config/huzhangsheng/HostPort" 80

注意:要使设置生效,请关掉 VirtualBox 再运行虚拟机,我把 VirtualBox 安装在 winxp 上,在虚拟机中安装 debian 4.02r ,虚拟机名是 debian ,并安装了 apache2 php5 mysql-server ,在主机上用IE浏览 http://localhost,成功转发到虚拟机 debian 的 apache2 web 服务器上,通过这点我发现:可能 VirtualBox 的设置比 vmware 更灵活,更强大。

相关推荐

    VirtualBox下Host Only+NAT方式的网络配置

    VirtualBox下Host Only+NAT方式的网络配置,供大家参考,具体内容如下 环境 宿主机Win8虚拟机Ubuntu有线连接(无线可以选择桥接模式) 需求 主机和虚拟机能互相ping通虚拟机能访问外网 步骤 1. 打开Vbox, 选择...

    VirtualBox网络配置[参照].pdf

    本文主要探讨了VirtualBox中的两种网络配置方式:NAT和Host Interface(主机接口)。 **NAT网络配置** NAT,全称为网络地址转换,是一种常见的网络连接方式。在VirtualBox中,使用NAT模式时,虚拟机的网络流量会...

    virtualbox虚拟机NAT模式下不能连接外网的解决方法

    给VirtualBox虚拟机(装载了Ubuntu16.04系统)配置了两张网卡,网络模式分别为“网络地址转换(NAT)”和“仅主机(Host-Only)适配器”,其中,enp0s3网卡(NAT)用于外网访问,而enp0s8网卡(Host-Only)用于主机...

    VirtualBox网络配置[归纳].pdf

    在配置VirtualBox网络时,主要有两种模式:NAT和Host Interface(也称为Host-Only或桥接网络)。这两种模式各有特点,适用于不同的使用场景。 1. **NAT模式**: - **工作原理**:NAT模式下,虚拟机通过主机上的...

    VirtualBox虚拟机网络设置(四种方式)

    ### VirtualBox虚拟机网络设置详解 #### 一、NAT网络地址转换模式 NAT模式是一种简化版的...无论是基础的互联网访问、真实的网络集成、封闭的内部网络环境,还是高级的主机网络配置,VirtualBox都能提供相应的支持。

    virtualbox网络配置参考

    ### VirtualBox网络配置详解 #### 一、NAT模式(NAT Mode) NAT模式是VirtualBox提供的最为简便的一种网络连接方式。在此模式下,虚拟机可以与宿主机进行通信,但不能直接与外部网络中的其他设备进行通信。具体而...

    Virtualbox NAT通过端口映射与主机实现远程连接和访问

    Virtualbox NAT 通过端口映射实现远程连接和访问,是 Virtualbox 中的一种网络配置模式。该模式允许物理主机通过 NAT Network Address Translation 将虚拟机的 IP 地址映射到物理主机的 IP 地址上,从而实现虚拟机的...

    VirtualBox中的网络配置方法

    本文将详细介绍VirtualBox提供的四种主要网络配置模式:Network Address Translation (NAT)、Bridged networking、Internal networking 和 Host-only networking,并给出实际应用场景示例。 #### 二、Network ...

    virtualbox网络配置

    本地虚拟机的网络配置,virtual box 网络连接

    在VirtualBox上配置网站服务器

    打开VirtualBox,点击:管理-全局配置-网络-新建网卡,然后对Net网络进行配置,设置网络CIDR和端口转发如图所示: 配置好网络后新建一个虚拟机,命名为centos7 server。其他的配置直接下一步按照默认就行,新建完后...

    VirtualBox配置固定IP和联网文档-致那些曾经踩过的坑

    在使用VirtualBox进行虚拟化部署时,经常会遇到一些网络配置上的问题,比如主机与虚拟机之间的网络不通、虚拟机无法上网或是虚拟机中的IP地址不稳定等。这些问题不仅会增加开发和调试的难度,还可能导致一些依赖于...

    VirtualBox网络设置

    这篇文章主要介绍了VirtualBox中的host-only和bridge配置教程,以及如何配置网络使虚拟机能够与主机进行通信和访问互联网。 host-only网络设置 在VirtualBox中,默认的网络方式是host-only方式。host-only方式...

    VirtualBox安装配置教程

    VirtualBox安装配置教程 ...VirtualBox安装配置教程非常简单易懂,即使是初学者也可以轻松地完成安装和配置。通过使用VirtualBox,用户可以在一台物理机器上运行多个虚拟机,每个虚拟机都可以独立运行不同的操作系统。

    virtualbox_virtual_box_网络各种配置方案_bridge

    在VirtualBox 的虚拟网络配置中,有四种主要的网络模式:NAT(Network Address Translation)、Bridged Adapter、Internal 和 Host-only Adapter。每种模式都有其特定的用途和优势,适用于不同的场景。 ### 1. NAT ...

    VirtualBox网络配置

    VirtualBox网络配置,Virtual如何配置网络,虚拟机网络的类型,如何与Host机通讯,虚拟机之间如何通讯,讲的是这些

    详解VirtualBox虚拟机网络环境解析和搭建-NAT、桥接、Host-Only、Internal、端口映射

    本篇文章主要是介绍详解VirtualBox虚拟机网络环境解析和搭建-NAT、桥接、Host-Only、Internal、端口映射,有兴趣的可以了解一下。

    Oracle Virtualbox Host-Only网络的设置

    此文介绍Oracle Virtualbox Host-Only网络的设置。 虚拟机里的操作系统是oracle linux 7。 创作的kubernetes虚拟机的配置之一。 关于kubernetes虚拟机下载,请参考。 ...

    VirtualBox安装CentOS7的配置.rar

    本文将详细介绍如何使用VirtualBox安装CentOS7,并进行必要的网络配置。 首先,我们需要了解VirtualBox的基本概念。VirtualBox是由德国公司Oracle开发的一款虚拟机软件,它可以在一台物理主机上创建和运行多个操作...

    virtualBox+rhel-server 6.5 Host-Only模式配置ip互ping

    virtualBox+rhel-server 6.5 Host-Only模式配置ip互ping 亲测有效

Global site tag (gtag.js) - Google Analytics