VirtualBox设置Ubuntu的添加Host-Only网卡

本文介绍如何在VirtualBox中为Ubuntu虚拟机配置双网卡,包括NAT模式和Host-Only模式,实现内外网同时访问,并配置SSH服务以便从宿主机远程登录。

背景

在首次在VirtualBox上面安装好Ubuntu之后,就想到要能够通过我自己的实体机器的命令行终端操作,而不用跑到VirtualBox界面去操作命令行就好了。

主要思路

VirtualBox的网络模式了解

在VirtualBox上面安装好Ubuntu之后,默认是设置该虚拟机的网络模式是为NAT模式,这样就保证了,虚拟机Ubuntu能够上网,并能够正常安装相关软件包,好处还是满多的,当时还是不能直接通过实体机器命令行终端访问。

Network Address Translation (NAT) 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.

若想能够让实体机器访问虚拟机,就通过Host-only模式吧!看到这里,主要思路就出来了给虚拟机添加一个Host-Only网卡就可以了,这样就可以获得原来NAT访问网络的好处,也获得实体命令终端的便利。

给VirtualBox添加Host-Only网卡

在VirtualBox的偏好设置里面添加Host-Only网卡:

Host-Only网卡Note:是VirtualBox的偏好设置,不是某个虚拟机的偏好设置。

给Ubuntu虚拟机添加Host-Only网卡

某个虚拟机设置 然后,选择【网络】>【网卡2】(启用网络连接)>【连接方式:仅主机(Host-Only)网络】>【界面名称:vboxnet0】>【OK】 为虚拟机添加Host-Only网卡Note:这里是为某个虚拟机进行网卡添加,而不是VirtualBox里面的设置,而且,必须进行【给VirtualBox添加Host-Only网卡】这个步骤,才能够为某个虚拟机添加Host-Onley网卡。

Ubuntu操作系统中添加Host-Only网卡配置

这里就是普通的Linux网卡添加了,首先使用ifconfig -a 命令找到没有ip地址的网卡,然后,将该网卡添加到/etc/network/interfaces文件中,最后,重启服务器即可。

查询所有网卡

这里发现enp0s8是没有启用的网卡,接下来找到/etc/network/interfaces文件进行配置,这里使用vi进行编辑:

sudo vi /etc/network/interfaces

添加对Host-Only的配置

  # The host-only network interface
auto enp0s8
iface enp0s8 inet static
address 192.168.56.88
netmask 255.255.255.0
network 192.168.56.0
broadcast 192.168.56.255

在使用,ifup命令挂载新添加的网卡即可:

sudo ifup enps0s8

或者使用reboot重启。

配置Ubuntu的ssh服务

sudo apt-get install openssh-server

安装好ssh-server就可以通过实体机器终端访问了。

参考

Host-Only Networking with VirtualBox VirtualBox下为Ubuntu虚机添加第二块网卡

转载于:https://my.oschina.net/fxtxz2/blog/1858953

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值