windows ping通了虛擬機器就能通過xshell連線虛擬機器,然後通過xshell方便的操作虛擬機器操作。 主要是可以複製貼上命令和rz傳輸檔案到虛擬機器,以及虛擬機器當做內網伺服器
1. 檢視windows的ip和閘道器
- 在windows cmd中中使用
ipconfig
命令 - 注意這裡有很多的資訊只需要關注第一個(乙太網介面卡)我這裡的ip是
10.17.7.101
,閘道器是10.17.7.97
(這2資訊很關鍵,沒找對這2資訊隨便怎麼配都不行)

2. 在VMWare中配置ip和閘道器
A) VMWare中找到 編輯->虛擬網路編輯->更改設定

B) 設定網段
1 選擇VMnet8
2 選擇NAT模式,以及將主機虛擬機器介面卡連線到此網路
3 修改子網IP(這IP就是第一步得到的10.17.7.101
,的最後1位改為0.所以這裡得到10.17.7.0
),同時注意子網掩碼
4 點選NAT設定進入下一步

c) 設定閘道器我這裡是10.17.7.97

3. 修改interfaces檔案 sudo vim /etc/network/interfaces
增加如下內容,其中ens33代表的是網路卡,當然有的不是ens33有的是eth0等。通過ifconfig
就能檢視
auto ens33
開機自動啟動網路卡
iface ens33 inet static
代表使用靜態ip
address 10.17.7.102
為本機設定的ip(和windows的ip不重複就行)
netmask 255.255.255.0
子網掩碼
gateway 10.17.7.97
閘道器先前找的那個
dns-nameserver 223.5.5.5
指定DNS伺服器(不需要改/etc/resolv.conf
這檔案,因為會被interfaces檔案覆蓋)
auto lo
iface lo inet loopback
auto ens33
iface ens33 inet static
address 10.17.7.102
netmask 255.255.255.0
gateway 10.17.7.97
dns-nameserver 223.5.5.5
複製程式碼

4. 重啟服務sudo /etc/init.d/networking restart
ubuntu server版這命令就可以了。當然如果是ubuntu桌面版,這個命令還不行,必須重啟虛擬機器。

5. 測試
看到自己設定的ip說明已經成功了。


6. xshell連線虛擬機器
xshell連線命令ssh 10.17.7.102
如果連不上虛擬機器可以看xshell能ping通虛擬機器,不能連線虛擬機器

7. 總結
其實主要是為了讓虛擬機器和windows處在同一個網段和閘道器,這樣就能ping通。