lesson02 关于virtualbox 安装centos 时6种网络连接选择的异同

一、背景:

小白在mac os 上安装virtualbox 用与虚拟安装linux centos 环境熟悉linux 命令。

  1. Mac OS  10.13
  2. Virtualbox 已经安装完成: virtualbox for Mac
  3. 本案例安装的是linux 下的centos 版本redhat

二、过程:打开Virtualbox  manager 界面,安装新虚拟机的过程:

new —-name:test—-select  linux —redhat

—分配内存1g(本机的1/4),

—-创建虚拟盘—格式—vdi disk image 光盘映像—-硬盘分配模式:动态分配适合节省空间,固定分配速度更快,因为磁盘空间不像动态分配那样分散,而是连续的空间,所以速度会快

——配置此虚拟机的network,问题如下

——-storage 界面挂载光盘,控制器sata =虚拟硬盘, ide controller=虚拟光驱,把下载好的centos .iso 挂载到此——–启动start 虚拟机—-开始进入centos 安装界面—-skip disk check—-语言设置—-存储设备—选择分配好的虚拟硬盘—选择存放位置—setting host name—-setting network—-wired: 自动连接,—-ipv4 setting:1.method:自动获取(DHCP)如果家里路由是自动获取可以这样选,但是如果是做web server 等服务器还是不要这种动态获取,最好选静态获取ip ,所以此处我们选“手工设置”:填写ip adress, 掩码24不用改,gateway:网关是指家里路由器的地址,dns 服务,比如电信的网址,——–时区—–超级用户设置——安装哪种base server,参考link: —-选择basic server—-

安装过程中的问题:

VB –setting — network 网络连接的6种不同选择:
netlink

  1. NAT
    • NAT即为网络地址转换,通常它的名称为VMnet8,通过nat的连接方式可以使得虚拟机和真实机的网卡在不同的网段中,从而实现联网。
    • 网络地址转换:相当于把虚拟机的端口映射到本机(宿主机)的端口,
    • 这种选择可能会使得外部网络/设备访问虚拟机产生一些问题
  2.  NAT Network
    • Network Address Transaction,主要是将虚拟机的虚拟网络地址转化成现实网络中的可用地址,主要有三种形式:静态转换Static Nat动态转换Dynamic Nat 端口多路复用OverLoad。
       
      静态转换和动态转换,顾名思义,就是转化地址映射表是静态还是动态的区别。而虚拟机实现的方式是端口多路复用,也就是说host machine的地址: ip1:port1, guest machine的地址ip2:port1在通过host machine的NAT转换后就变成了ip1:port2,从而与外界网络交流。
      这样的情形下,对于外界的网络而言,是不知道ip1:port2的包到底是guest machine发出来的还是host machine发出来的,自然也就无法去访问guest machine,从而这样的NAT实现的网络是单向的:虚拟机可以访问外部网络,而主机和其他虚拟机都无法访问虚拟机。
      如果在这个模式下实现相互访问,那么就得用到端口映射了,用过emule的同学都知道,为了使局域网内的ip也能够被ED2K网络上其他用户检测到,实现文件共享,那么就要在路由上做端口映射,使得路由器知道,在这个端口上受到的包都转发给特定的ip;在这里也是一样的,既设置规则,对于所有的port2端口受到的package都转发给ip2:port1既虚拟机的网络地址,外部网络就能够通过这样一个隧道来和虚拟机交互了。
    • def:this is a marriage between NAT and Internal Network and provides the benefits of both. Virtual machines can communicate amongst themselves without involving the host and can also establish outbound connectivity where necessary (as per the NAT mode described previously). Externally initiated inbound connections require Port Forwarding is configured. For internet access via proxy, the host’s proxy configuration needs to be duplicated on the guest (it won’t be inherited).

      VirtualBox can provide DHCP services for this network mode.

      A NAT Network must be created before a guest interface can be assigned to it, via File > Preferences > Network > NAT Networks.

    • NAT is the simplest option from the point of view of the guest system for accessing external networks. External access to the guest system (such as accessing a web server installed on a guest system) is not possible.[4]

      Note: Even from the host system, the services on the guest system cannot be accessed. If access should be possible, an additional interface can be configured using Host-only networking.

  3. Bridged Adapter:
    • bridge即为桥接,通常它的名称为VMnet0,使用桥接的方式使得自己的虚拟机和自己的真实机网卡在同一个网段,从而实现联网。
    • 桥接网卡: 推荐,能最大程度上模拟真实的服务器环境。适合于部署ftp 等,
    • 这个选择就当把虚拟机想象成真正的电脑,跟host 这个本地电脑一样用网线连着同一个交换机。
    • On Macintosh hosts, functionality is limited when using AirPort (the Mac’s wireless networking) for bridged networking. Currently, VirtualBox supports only IPv4 and IPv6 over AirPort. For other protocols (such as IPX), you must choose a wired interface. 如果宿主机是苹果系统,连接的是无线网络热点,选择桥接网络会有限制,
    • 辅助资料:苹果手机iPhone手机如何查看ip地址和网关

    • Bridged networking not working with wifi (mavericks)
    • With NAT selected, on the guest machine I can access the internet.
      With Bridged (en4: USB Ethernet) all is okWith Bridged (en0: Wi-Fi (AirPort)) selected I can’t get an ip address (v4) on the guest so can’t access the internet.
      This is very frustrating, please help (let me know if you need to see the output of any other commands).
    • In this mode, the guest system will receive direct access to the network, to which the host system has been connected.[5]
    • This allows you to fully integrate the guest into any network the host is a part of/connected to. You select one of your host’s network interfaces and, logically speaking, the guest is then connected to the same network (the physical and virtual interfaces are bridged). It can obtain (or be statically assigned) an IP address as if it were cabled to that network. The guest can then communicate with the host and visa versa. The guest can also accept externally initiated inbound connections without the need for Port Forwarding or NAT/PAT.

      In Vagrant terminology, this is a public_network. In Docker, this is called Host mode.

      VirtualBox can not provide DHCP services for this network mode.

  4. Internal Network
    • 顾名思义,就是内部网络,virtualBox等于提供了一个虚拟交换机,配置了internal的虚拟机发送的package都通过这个虚拟的交换机,而这个路由是和外部的网络,host机器都没有关系的;于是只有在同一个internal ID网络下的虚拟机之间可以互相访问。
    • 这样,这些虚拟机之间的相互交互的data就完全不通过物理网络接口,安全性得到了提高。
  5. Host-only Adapter
    • host-only即为仅主机,通常它的名称是VMnet1,使用host-only的方式是不能和外界通信的,只能够和本机的物理网卡通信。
    • 有点类似于bridged adapter和internal的混合体,虚拟机之间是通过internal mode相互连接访问,而virtualBox会在host上建立一个软件“loopback” interface,而虚拟机就通过这个接口作为与host之间交流的通道。如同建立了在这个接口上建立了一个新的子网,而所有的虚拟机都在这个子网上。
    • 不通的modes之间的连通性关系如下图:
    • A ‘private’ network connecting the host (via a loopback interface) and one or more guests. This allows for simple host network connectivity, for administrative purposes, to guests, without the use of Port Forwarding. If you intend to use SSH or HTTP/S to manage your guests, connecting them to this network is very useful.

      Multiple host-only networks (and host loopback interfaces) can be configured.

      VirtualBox can provide DHCP services with this network mode.

      A Host-only Network must be created before a guest interface can be assigned to it, via File > Preferences > Network > Host-only Networks.

  6. Generic Driver
    • There are currently two possible sub-modes for Generic networking mode:
      • UDP Tunnel[8]
      • VDE (Virtual Distributed Ethernet) networking[9]

 

 


参考资料及其引用源:

  1. https://jingyan.baidu.com/article/4e5b3e1957979d91901e24f1.html
  2. https://blog.csdn.net/bbplayers/article/details/7201347
  3. https://ask.csdn.net/questions/516261
  4. Chapter 6. Virtual networking
  5. Network Configuration in VirtualBox
  6. Oracle VirtualBox Network Mode
此条目发表在Linux分类目录。将固定链接加入收藏夹。