How to configure the network connection between the client and VirtualBox host

How to configure the network connection between the client and VirtualBox host

Author: Aaron Kili Translator: LCTT  rusking

| 2017-03-01 13:40 Comments: 3  Favorites: 3    

When you are in a VirtualBox virtual machine software when installed in a variety of operating systems, you may need to implement mutual access between the host and the virtual machines.

In this article, we will be the most straightforward way to illustrate how to configure a network client and Linux host, in order to achieve the two visit each other or let the client to connect to external networks. (LCTT Annotation: client refers to the operating system Oracle VirtualBox virtual machine software installed, as used herein, CentOS 7 and Ubuntu 16.10 host is your own laptop or desktop machine, pay attention to this article, the author places. installed on the host operating system is Linux Mint 18, rather than the Windows system we usually use.)

In this paper the test environment: 1, the host operating system - Linux Mint 18 2, the client operating system - CentOS 7 and Ubuntu 16.10

Claim

  1. Installation of VirtualBox virtual machine on the host computer can be used normally.
  2. You have to pre-installed virtual machine software in Oracle virtualBox in good guest operating systems, such as Ubuntu, Fedora, CentOS, Linux Mint or other Linux systems is required.
  3. Before you configure your network, turn off the client.

In order to be able to host and client communicated with each other, these two machines must be set to the default LAN IP in the same network segment, you can add up to four NICs for the client.

Default NIC (NIC1) commonly connected using NAT, and the host connected to the Internet.

Important: The first NIC generally always provided in communication with the sink host, network card connected to a second external network.

Create a card for the client and host

In the following VirtualBox Manager interface, create a communication between a client card and the host.

Open File -> Preferences to configure, or use the key combination  Ctrl + G:

Virtualbox Preferences screen

Virtualbox Preferences screen

In the following figure there are two options, click and select only the host (Host-only) network. Then use the right side +to add a new host-only network button.

Setting up the client network

Setting up the client network

This will create a new card only host mode called vboxnet0 of.

If you prefer, you can use the middle - button to remove this card, you can click on the Edit button to view detailed configuration information about the NIC.

You can also configure information according to their actual environmental changes, such as network address, subnet mask, and so on.

Note: IPv4 address in the following figure is the IP address of your host machine.

Host network information

Host network information

The following diagram, if you want the client to use dynamic IP addresses, you can do so by configuring the DHCP service (before use be sure to enable DHCP). But I recommend that you configure a static IP address for the client.

In the following set all the network interface, click the OK button to save the modified configuration.

Set a static IP address for the client

Set a static IP address for the client

Configuring client network settings

Note: You can add any card is required to communicate with the host client according to the following steps.

Back to the VirtualBox Manager interface, select the client, such as Ubuntu 16.10 Server or CentOS 7, and then click the Settings menu.

Configuring client network settings

Configuring client network settings

Configuring the client card to connect to the host

Select Network option from the interface of FIG. Then configure the first NIC (NIC1) information is as follows:

  1. Check the option: "Enable card" to open the card.
  2. In connection option: Select only the host (Host-only) network.
  3. Then select the card name: vboxnet0

As shown below, click OK to save the settings:

Enable Client Network

Enable Client Network

Configuring the client network card to connect to external networks

After the addition of the second NIC (NIC2) to allow the client to connect to the host to access the Internet. Use the following settings:

  1. Check the option: "Enable network connections" to activate this card.
  2. In connection options: Select NAT mode.

Enable Network Adapter for VM

Enable Network Adapter for VM

为客户机启用网络连接

为客户机设置静态 IP 地址

启动客户机,登录系统并配置静态 IP 地址。在客户机上执行下面的命令来查看所有网卡配置信息,然后分配一个 IP 地址:

  1. $ ip add

Configure a static IP address for the client

为客户机配置静态 IP 地址

从上面的截图中可以看出客户机已启用了三块网卡:

  1. lo ——回环网络接口
  2. enp0s3 (网卡 1)—— 前一步我们配置的连接方式为仅主机( Host-Only)模式并且已启用 DHCP 的网卡,之后我们又配置成了静态 IP 地址。
  3. enp0s8 (网卡 2)—— 用于连接到外网。该网卡默认情况下使用 DHCP 来动态获取 IP 地址。
在 Debian/Ubuntu/Linux Mint 系统下的配置

重要提示: 这里我使用的是 Ubuntu 16.10 Server , IP 地址为 192.168.56.5 。

使用你喜欢的编辑器及管理员账号打开 /etc/network/interfaces 配置文件:

  1. $ sudo vi /etc/network/interfaces

修改网卡 enp0s3 的配置信息如下(根据你的实际环境进行修改):

  1. auto enp0s3
  2. iface enp0s3 inet static
  3. address 192.168.56.5
  4. network 192.168.56.0
  5. netmask 255.255.255.0
  6. gateway 192.168.56.1
  7. dns-nameservers 8.8.8.8 192.168.56.1

保存并退出。

然后使用下面的命令来重启网络服务:

  1. $ sudo systemctl restart networking

或者,正常重启系统,然后检查网络配置是否为新的 IP 地址:

  1. $ ip add
在 RHEL/CentOS/Fedora 系统下的配置

重要提示: 这里我使用的是 CentOS 7 系统, IP 地址为: 192.168.56.10 。

使用管理员帐号及你喜欢的编辑器打开 enp0s3 (仅主机网络)的网卡配置文件 /etc/sysconfig/network-scripts/ifcfg-enp0s3

  1. $ sudo vi /etc/sysconfig/network-scripts/ifcfg-enp0s3

创建或修改配置文件信息如下(根据你实际的环境进行修改):

  1. BOOTPROTO=static
  2. ONBOOT=yes
  3. IPADDR=192.168.56.10
  4. NETWORK=192.168.56.0
  5. NETMASK=255.255.255.0
  6. GATEWAY=192.168.56.1
  7. DNS=8.8.8.8 192.168.56.1
  8. NM_CONTROLLED=no #use this file not network manager to manage interface

保存并退出。然后使用下面的命令重启网络服务(也可以重启系统):

  1. $ sudo systemctl restart network.service

检查修改的配置地信息是否生效:

  1. $ ip add

在宿主机上使用 SSH 工具来管理客户机

在宿主机上使用 SSH 工具来管理你的客户机。在下面的实例中,我将使用 SSH 工具连接到 CentOS 7 服务器(192.168.56.10):

  1. $ ssh tecmint@192.168.56.10
  2. $ who

SSH client connection using a tool

使用 SSH 工具连接客户机

Finish here! In this article, we use the straightforward method describes how to set up a network connection between the host and client mode. Please share in the comments section below under your thoughts with you.


About the Author:

Aaron Kili is a Linux and FOSS enthusiasts, is about to engage in a Linux system administrators and web-development work, he was recently the site of the original author TecMint technology, very much like working with computers, convinced that sharing knowledge is a virtue.


via: http://www.tecmint.com/network-between-guest-vm-and-host-virtualbox/

Author: Aaron Kili Translator: rusking proofread: Bestony

This article from the LCTT original compiler, Linux China is proud

Guess you like

Origin www.cnblogs.com/jiftle/p/10980139.html
Recommended