在首次在VirtualBox上面安裝好Ubuntu以後,就想到要可以經過我本身的實體機器的命令行終端操做,而不用跑到VirtualBox界面去操做命令行就行了。web
在VirtualBox上面安裝好Ubuntu以後,默認是設置該虛擬機的網絡模式是爲NAT模式,這樣就保證了,虛擬機Ubuntu可以上網,並可以正常安裝相關軟件包,好處仍是滿多的,當時仍是不能直接經過實體機器命令行終端訪問。shell
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網卡:ssh
Note:是VirtualBox的偏好設置,不是某個虛擬機的偏好設置。操作系統
而後,選擇【網絡】>【網卡2】(啓用網絡鏈接)>【鏈接方式:僅主機(Host-Only)網絡】>【界面名稱:vboxnet0】>【OK】
Note:這裏是爲某個虛擬機進行網卡添加,而不是VirtualBox裏面的設置,並且,必須進行【給VirtualBox添加Host-Only網卡】這個步驟,纔可以爲某個虛擬機添加Host-Onley網卡。.net
這裏就是普通的Linux網卡添加了,首先使用ifconfig -a 命令找到沒有ip地址的網卡,而後,將該網卡添加到/etc/network/interfaces文件中,最後,重啓服務器便可。命令行
這裏發現enp0s8是沒有啓用的網卡,接下來找到/etc/network/interfaces文件進行配置,這裏使用vi進行編輯:code
sudo vi /etc/network/interfaces
# 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命令掛載新添加的網卡便可:server
sudo ifup enps0s8
或者使用reboot重啓。
sudo apt-get install openssh-server
安裝好ssh-server就能夠經過實體機器終端訪問了。
Host-Only Networking with VirtualBox VirtualBox下爲Ubuntu虛機添加第二塊網卡