1. 程式人生 > >macOS版VMware Fusion 8的vmnet8設置

macOS版VMware Fusion 8的vmnet8設置

ipv6 car each hash urg 解決問題 lib fig mas

    • 需求:虛擬機使用NAT模式,自動獲取10.0.0.0/24的IP地址,網關是10.0.0.254,虛擬機可以ping通 www.baidu.com
    • 科普:NAT模式使用vmnet8網卡
      • NAT(Network Address Translation,網絡地址轉換),NAT模式是比較簡單的實現虛擬機上網的方式。簡單地理解,NAT模式的虛擬機就是通過宿主機(物理計算機)上網和交換數據的。
      • 在NAT模式下,虛擬機的網卡連接到宿主機的VMnet8上。此時系統的VMware NAT Service服務就充當了路由器,負責將虛擬機發送到VMnet8的包進行地址轉換之後發送到實際的網絡上,再將實際網絡上返回的包進行地址轉換後通過VMnet8發送給虛擬機。VMware DHCP Service負責為虛擬機分配IP地址。
      • NAT網絡特別適合於家庭裏計算機直接連接網線的情況,當然辦公室的局域網環境也是適合的,其優勢是不會與其他物理主機IP沖突,且在沒有路由的環境下也可以通過SSH NAT連接虛擬機學習,換了網絡環境虛擬機IP等不受影響,這是老男孩推薦的選擇。
      • 由於macOS平臺下的VMware Fusion 8軟件不具備“虛擬網絡編輯器”功能,必須通過修改兩個配置文件來實現對NAT模式的配置
        • “虛擬網卡編輯器”配置文件
          /Library/Preferences/VMware\ Fusion/networking
        • “vmnet8默認網關”配置文件
          /Library/Preferences/VMware\ Fusion/vmnet8/nat.conf
    • 解決問題:在root身份下修改兩個配置文件
      • 第零步:切換到root身份下
        • $ sudo su
      • 第一步:修改“虛擬網卡編輯器”配置文件
        • $ cp /Library/Preferences/VMware\ Fusion/networking{,.bak}
          # 先備份源文件,避免改錯配置之後造成配置文件損壞
        • $ vim /Library/Preferences/VMware\ Fusion/networking
          • 默認配置如下(修改前的狀態)
            VERSION=1,0
            answer VNET_1_DHCP yes
            answer VNET_1_DHCP_CFG_HASH BBDD0CB0C52A2FFF44945811CE493B7216FA3BAE
            answer VNET_1_HOSTONLY_NETMASK 255.255.255.0
            answer VNET_1_HOSTONLY_SUBNET 192.168.38.0
            answer VNET_1_VIRTUAL_ADAPTER yes
            answer VNET_2_VIRTUAL_ADAPTER no
            answer VNET_8_DHCP yes
            answer VNET_8_DHCP_CFG_HASH 02CB138B4747CCA0E3A6F8274E3C26A790519B77
            answer VNET_8_HOSTONLY_NETMASK 255.255.255.0
            answer VNET_8_HOSTONLY_SUBNET 192.168.78.0
            answer VNET_8_NAT yes
            answer VNET_8_VIRTUAL_ADAPTER yes
            add_bridge_mapping en0 2
          • 將 answer VNET_8_HOSTONLY_SUBNET 這一項後面的地址改為 10.0.0.0
          • :wq 保存退出
      • 第二步:修改“vmnet8默認網關”配置文件
        • cp /Library/Preferences/VMware\ Fusion/vmnet8/nat.conf{,.bak}
          # 先備份源文件,避免改錯配置之後造成配置文件損壞
        • $ vim /Library/Preferences/VMware\ Fusion/vmnet8/nat.conf
          • 默認配置如下(修改前的狀態)
            # VMware NAT configuration file
            [host]
            # NAT gateway address
            ip = 192.168.78.2
            netmask = 255.255.255.0
            # VMnet device if not specified on command line
            device = vmnet8
            # Allow PORT/EPRT FTP commands (they need incoming TCP stream ...)
            activeFTP = 1
            # Allows the source to have any OUI. Turn this on if you change the OUI
            # in the MAC address of your virtual machines.
            allowAnyOUI = 1
            # Controls if (TCP) connections should be reset when the adapter they are
            # bound to goes down
            resetConnectionOnLinkDown = 1
            # Controls if (TCP) connection should be reset when guest packet‘s destination
            # is NAT‘s IP address
            resetConnectionOnDestLocalHost = 1
            # Controls if enable nat ipv6
            natIp6Enable = 0
            # Controls if enable nat ipv6
            natIp6Prefix = fd15:4ba5:5a2b:1008::/64
            [tcp]
            # Value of timeout in TCP TIME_WAIT state, in seconds
            timeWaitTimeout = 30
            [udp]
            # Timeout in seconds. Dynamically-created UDP mappings will purged if
            # idle for this duration of time 0 = no timeout, default = 60; real
            # value might be up to 100% longer
            timeout = 60
            [netbios]
            # Timeout for NBNS queries.
            nbnsTimeout = 2
            # Number of retries for each NBNS query.
            nbnsRetries = 3
            # Timeout for NBDS queries.
            nbdsTimeout = 3
            [incomingtcp]
            # Use these with care - anyone can enter into your VM through these...
            # The format and example are as follows:
            #<external port number> = <VM‘s IP address>:<VM‘s port number>
            #8080 = 172.16.3.128:80
            [incomingudp]
            # UDP port forwarding example
            #6000 = 172.16.3.0:6001
          • (找到 # NAT gateway address 的下一行)將 ip = 192.168.78.2 這一項的地址改為 10.0.0.254
          • :wq 保存退出
      • 第三步:先關閉正在運行的虛擬機,然後退出VMware Fusion軟件,再重新打開VMware Fusion軟件,正常啟動虛擬機即可
      • 第四步:記得退出root身份的登錄狀態
        • $ exit
          # 也可以按 Command+R 兩個鍵,效果等價

macOS版VMware Fusion 8的vmnet8設置