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

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 = 172.16.58.1                 #这个 ip 就是本机网关地址
    netmask = 255.255.255.0          #这个就是本机子网掩码
    

    网关地址:172.16.58.1

    子网掩码:255.255.255.0

  • 查看 dhcpd.conf 内容:

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

    得到静态 IP 访问:172.16.58.128 - 172.16.58.254

2. 查看本机 DNS

Mac 上 VMware 设置虚拟机为静态 IPMac 上 VMware 设置虚拟机为静态 IPMac 上 VMware 设置虚拟机为静态 IP

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

  • 保存

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

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

4. 检查配置是否成功

  • 看控制面板:

    Mac 上 VMware 设置虚拟机为静态 IP
  • 虚拟机上 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 172.16.58.201
    PING 172.16.58.201 (172.16.58.201): 56 data bytes
    64 bytes from 172.16.58.201: icmp_seq=0 ttl=64 time=0.317 ms
    64 bytes from 172.16.58.201: icmp_seq=1 ttl=64 time=0.415 ms
    64 bytes from 172.16.58.201: icmp_seq=2 ttl=64 time=0.453 ms
    
  • 没有问题,配置完成。

上一篇:oracle 下操作blob字段是否会产生大量redo


下一篇:vim替换命令进阶实践--Linux编码风格到小驼峰