天天看點

VirtualBox + Centos 使用NAT + Host-Only 方式聯網

一、準備工作

  1. VirtualBox

       2. CentOS鏡像

       備注:我這裡準備好了需要下載下傳的檔案,有需要的話可以下載下傳一下,分别是VirtualBox-5.1.24-117012-Win.exe,CentOS-7-x86_64-Minimal-1611.iso。

       位址:連結:https://pan.baidu.com/s/1ki2Qvuwc_-mgoAMQkN5n4A       密碼:uwwf

二、VirtualBox安裝

        這邊暫時不寫了,有時間會補充的。

三、VirtualBox內建CentOs

  點選建立菜單,輸入名稱、選擇類型和版本,如圖

                                                                             

VirtualBox + Centos 使用NAT + Host-Only 方式聯網
        點選下一步,這裡是設定虛拟電腦的記憶體,我們設定1G就可以了,在公司裡一般是8G/16G的,如圖
VirtualBox + Centos 使用NAT + Host-Only 方式聯網
        點選下一步
VirtualBox + Centos 使用NAT + Host-Only 方式聯網
                                                                                             
VirtualBox + Centos 使用NAT + Host-Only 方式聯網
VirtualBox + Centos 使用NAT + Host-Only 方式聯網
        下一步,這裡是設定虛拟硬碟的大小,大家可以根據情況設定,我這裡隻設定8G
VirtualBox + Centos 使用NAT + Host-Only 方式聯網
       點選建立,就完成了。就可以看到我們建立的centos了。
VirtualBox + Centos 使用NAT + Host-Only 方式聯網
         點選啟動,會彈出下面的圖形,這裡我們選擇我們下載下傳的 CentOS-7-x86_64-Minimal-1611.iso,然後啟動。
VirtualBox + Centos 使用NAT + Host-Only 方式聯網
VirtualBox + Centos 使用NAT + Host-Only 方式聯網
            Enter進入。
VirtualBox + Centos 使用NAT + Host-Only 方式聯網
            點選Continue,可能需要點兩次。
VirtualBox + Centos 使用NAT + Host-Only 方式聯網
           點進去,然後點選左上角的done,就可以了
VirtualBox + Centos 使用NAT + Host-Only 方式聯網
VirtualBox + Centos 使用NAT + Host-Only 方式聯網
          Begin Installation
VirtualBox + Centos 使用NAT + Host-Only 方式聯網
             設定密碼和确定密碼,我們設定密碼的時候,有時候我們設定的密碼過于簡單,會提示太簡單了,但是我們可以強制使用這個密碼,點選Done兩次完成。
VirtualBox + Centos 使用NAT + Host-Only 方式聯網
VirtualBox + Centos 使用NAT + Host-Only 方式聯網
VirtualBox + Centos 使用NAT + Host-Only 方式聯網
          Reboot重新開機。
VirtualBox + Centos 使用NAT + Host-Only 方式聯網
          點選Enter
VirtualBox + Centos 使用NAT + Host-Only 方式聯網

                     輸入使用者名和密碼,使用者名為root,密碼是自己設定的密碼。

                     到這一步,準備工作就完成了。

四、配置網絡

      ① 先關閉虛拟電腦

VirtualBox + Centos 使用NAT + Host-Only 方式聯網
② 在 VirtualBox 主要制界面點選 【管理】--【全局設定】--【網絡】--【添加新NAT網絡】
VirtualBox + Centos 使用NAT + Host-Only 方式聯網
③ 在彈出的對話框中,設定【網絡CIDR】為【192.168.100.0/24】,【确定】
VirtualBox + Centos 使用NAT + Host-Only 方式聯網

④ 在管理界面點選【設定】--【網絡】--【網卡1】,【連接配接方式】選擇【NAT網絡】,【界面名稱】選【NATNetwork】,【确定】

⑤ 【啟動】

登陸進系統之後,運作:

ip addr      
VirtualBox + Centos 使用NAT + Host-Only 方式聯網

注意:有可能顯示的不一樣,我這裡顯示的是enp0s3,是以運作下面的指令

vi /etc/sysconfig/network-scripts/ifcfg-enp0s3      
VirtualBox + Centos 使用NAT + Host-Only 方式聯網

把ONBOOT=no  改成ONBOOT=yes

運作下面的指令,重新開機服務

service network restart      
VirtualBox + Centos 使用NAT + Host-Only 方式聯網

這個時候就可以通路外網了

VirtualBox + Centos 使用NAT + Host-Only 方式聯網

關閉系統,

回到VirtualBox  點選設定

VirtualBox + Centos 使用NAT + Host-Only 方式聯網
VirtualBox + Centos 使用NAT + Host-Only 方式聯網

然後ok完成了,啟動虛拟電腦,進入系統。

為了更好的看位址,我們可以運作下面的指令,中間需要輸入兩次y,直到安裝成功。

yum install net-tools      

輸入指令檢視ip位址

ifconfig      
VirtualBox + Centos 使用NAT + Host-Only 方式聯網

 通過用SSH就可以連接配接  192.168.56.102:22  了。