问题描述
上一篇文章中已经介绍了ubuntu系统在虚拟机中的安装,安装过后发现主机可以ping通虚拟机,可是虚拟机ping不通主机。
环境查看
主机网络
虚拟服务器网络
装完系统之后通过 ifconfig 命令只看到这两个网卡信息。这里请忽略马赛克部分。
解决步骤
打开VirtualBox,选择虚拟机,右键点击设置。进入设置页面后,选择网卡2点勾选启用,并按照图示完成其他配置。
重新启动系统,进入系统后输入以下命令查看系统网卡:
ls /sys/class/net
发现多了一个enp0s8
接下来配置这个网卡ip,首先切入到root用户
sudo su root
编辑 interfaces
sudo vim /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
source /etc/network/interfaces.d/*
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface(NAT)
auto enp0s3
iface enp0s3 inet dhcp
auto enp0s8
iface enp0s8 inet static
address 192.168.56.101
netmask 255.255.255.0
重启服务器
reboot
再次查看服务器ip信息
ifconfig
至此服务器网络设置完成。
更多请参考下面这篇文章