ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

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

2021-06-30 12:03:27  阅读:226  来源: 互联网

标签:-- IP 虚拟机 172.16 bytes Mac ifup 64 ifdown


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

img image-20210630114216685 image-20210630114256156

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

    image-20210630114745160

  • 保存

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

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

4. 检查配置是否成功

  • 看控制面板:

    image-20210630114906307
  • 虚拟机上 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
    
  • 没有问题,配置完成。

标签:--,IP,虚拟机,172.16,bytes,Mac,ifup,64,ifdown
来源: https://blog.csdn.net/Hedon954/article/details/118358145

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有