问题描述
VMware Fusion中虚拟机的IP总是不断变化,导致自己搭建的Hadoop、Spark集群的维护非常不方便, 所以就需要为虚拟机指定IP地址。
解决方案
dhcpd.conf文件
dhcpd.conf 文件记录了动态分配的IP地址段,以及mac地址绑定的IP
# Configuration file for ISC 2.0 vmnet-dhcpd operating on vmnet8.## This file was automatically generated by the VMware configuration program.# See Instructions below if you want to modify it.## We set domain-name-servers to make some DHCP clients happy# (dhclient as configured in SuSE, TurboLinux, etc.).# We also supply a domain name to make pump (Red Hat 6.x) happy.####### VMNET DHCP Configuration. Start of "DO NOT MODIFY SECTION" ###### Modification Instructions: This section of the configuration file contains# information generated by the configuration program. Do not modify this# section.# You are free to modify everything else. Also, this section must start # on a new line # This file will get backed up with a different name in the same directory # if this section is edited and you try to configure DHCP again.# Written at: 07/02/2016 03:48:07allow unknown-clients;default-lease-time 1800; # default is 30 minutesmax-lease-time 7200; # default is 2 hourssubnet 192.168.109.0 netmask 255.255.255.0 { range 192.168.109.128 192.168.109.254; option broadcast-address 192.168.109.255; option domain-name-servers 192.168.109.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 192.168.109.2; option routers 192.168.109.2;}host vmnet8 { hardware ethernet 00:50:56:C0:00:08; fixed-address 192.168.109.1; option domain-name-servers 0.0.0.0; option domain-name ""; option routers 0.0.0.0;}####### VMNET DHCP Configuration. End of "DO NOT MODIFY SECTION" #######
说明: "range 192.168.109.128 192.168.109.254" 是动态分配的IP地址段。
为虚拟机指定 IP
编辑 dhcpd.conf 文件
sudo vim /Library/Preferences/VMware\ Fusion/vmnet8/dhcpd.conf
在文件末尾添加以下配置
host master { hardware ethernet 00:0C:29:61:B0:BF; fixed-address 192.168.109.137;}host slave01 { hardware ethernet 00:0C:29:B8:B8:5c; fixed-address 192.168.109.139;}host slave02 { hardware ethernet 00:0C:29:0D:BE:68; fixed-address 192.168.109.138;}
虚拟机的 MAC 地址可以在 "网络适配器 -> 高级选项" 中查看到, fixed-address 后面的 IP 地址就是为虚拟机所指定的 IP 地址, IP 地址的范围需要在 range 后面指定的IP地址段范围内。