1. 查看本机网关和子网掩码

  • 进入 Mac 的 Temical,输入:

    $ cd /Library/Preferences/VMware\ Fusion/vmnet8
    $ ll
    total 32
    -rw-r--r--  1 root  wheel  1665  6 30 11:00 dhcpd.conf
    -rw-r--r--  1 root  wheel  1665  6 30 11:00 dhcpd.conf.bak
    -rw-r--r--  1 root  wheel  1682  6 30 11:00 nat.conf
    -rw-r--r--  1 root  wheel  1682  6 30 11:00 nat.conf.bak
    
  • 查看 nat.conf 内容:

    $ cat nat.conf
    # VMware NAT configuration file
    # Manual editing of this file is not recommended. Using UI is preferred.
    
    [host]
    
    # Use MacOS network virtualization API
    useMacosVmnetVirtApi = 1
    
    # NAT gateway address
    ip = xxx.xxx.xxx.xxx                 #这个 ip 就是本机网关地址
    netmask = 255.255.255.0          #这个就是本机子网掩码
    

    网关地址:xxx.xxx.xxx.xxx

    子网掩码:255.255.255.0

  • 查看 dhcpd.conf 内容:

    subnet xxx.xxx.xxx.0 netmask 255.255.255.0 {
    	range xxx.xxx.xxx.128 xxx.xxx.xxx.254 ;      # range 这个是虚拟机允许选择的静态ip地址范围,自定义的静态ip地址必须要在这个范围内
    	option broadcast-address xxx.xxx.xxx.xxx ;
    	option domain-name-servers xxx.xxx.xxx.xxx ;
    	option domain-name localdomain;
    	default-lease-time 1800;                # default is 30 minutes
    	max-lease-time 7200;                    # default is 2 hours
    	option netbios-name-servers xxx.xxx.xxx.xxx ;
    	option routers xxx.xxx.xxx.xxx ;
    }
    

    得到静态 IP 访问:xxx.xxx.xxx.128 - xxx.xxx.xxx.254

2. 查看本机 DNS

 -> 系统偏好设置 -> 网络 -> 高级 -> DNS -> DNS 服务器

3. 修改虚拟机静态 IP

  • 进入虚拟机的 network-scripts 目录:

    $ cd /etc/sysconfig/network-scripts/
    $ ls
    ifcfg-ens33  ifdown-isdn      ifup          ifup-plip      ifup-tunnel
    ifcfg-lo     ifdown-post      ifup-aliases  ifup-plusb     ifup-wireless
    ifdown       ifdown-ppp       ifup-bnep     ifup-post      init.ipv6-global
    ifdown-bnep  ifdown-routes    ifup-eth      ifup-ppp       network-functions
    ifdown-eth   ifdown-sit       ifup-ib       ifup-routes    network-functions-ipv6
    ifdown-ib    ifdown-Team      ifup-ippp     ifup-sit
    ifdown-ippp  ifdown-TeamPort  ifup-ipv6     ifup-Team
    ifdown-ipv6  ifdown-tunnel    ifup-isdn     ifup-TeamPort
    
  • 找到 ifcfg-en 开头的文件,上图中我的是 ifcfg-ens33

  • 使用 root 权限编辑 ifcfg-ens33

    Mac 上 VMware 设置虚拟机为静态 IP_Mac

  • 保存

  • 重启无网络服务,使配置生效:

    $ service network restart
    Restarting network (via systemctl):                        [  OK  ]
    

4. 检查配置是否成功

  • 看控制面板:

    Mac 上 VMware 设置虚拟机为静态 IP_vmware_02

  • 虚拟机上 ping 一下百度看看能不能成功:

    $ ping www.baidu.com
    PING www.a.shifen.com (180.101.49.12) 56(84) bytes of data.
    64 bytes from 180.101.49.12 (180.101.49.12): icmp_seq=1 ttl=38 time=36.9 ms
    64 bytes from 180.101.49.12 (180.101.49.12): icmp_seq=2 ttl=38 time=39.5 ms
    64 bytes from 180.101.49.12 (180.101.49.12): icmp_seq=3 ttl=38 time=43.0 ms
    
  • 主机 ping 一下虚拟机看看:

    $ ping xxx.xxx.xxx.201
    PING xxx.xxx.xxx.201 (xxx.xxx.xxx.201): 56 data bytes
    64 bytes from xxx.xxx.xxx.201: icmp_seq=0 ttl=64 time=0.317 ms
    64 bytes from xxx.xxx.xxx.201: icmp_seq=1 ttl=64 time=0.415 ms
    64 bytes from xxx.xxx.xxx.201: icmp_seq=2 ttl=64 time=0.453 ms
    
  • 没有问题,配置完成。