virtualbox虚拟机ubuntu无法上网

今天想要在虚拟机上安装redis,结果尽然发现虚拟机不能上网,根据网上的一顿操作,差点把自己心态搞崩,不过,最后还是集百家智慧,重要搞定了。

打开虚拟机的时候,果断 sudo apt-get install redis-server,结果发现不能上网,

ping www.baidu.com ,发现ping不同,顿时感觉不好了,于是去度娘搜了一波,过程极度坎坷,好在最后成功解决。

解决方法,配置双网卡,一个Nat模式,用来连接外网,一个host-only模式,用来虚拟机与主机之间进行交换。

一.配置Nat模式

全局设定--》网络--》添加

设置–>网络--》nat模式(网卡一)

二.设置host-only模式(网卡二)

点击管理–>主机网络管理器–>

设置–>网络--》host-only

配置文件  sudo vi /etc/network/interfaces

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface 网卡一
auto enp0s3
iface enp0s3 inet dhcp
up route add default gw 10.0.2.2 dev enp0s3 #网卡一默认走网关10.0.2.2
# The primary network interface2 网卡二
auto enp0s8
iface enp0s8 inet static
address 192.168.56.16
gateway 192.168.56.1
netmask 255.255.255.0
broadcast 192.168.56.255

最后都可以ping通

ping www.baidu.com

ping主机

文章目录
|
载入天数...载入时分秒...