在Fusion下设置固定IP

最近在Mac上用Fusion跑Linux,主要是用来做server端的开发,但是在开发过程中发现,虚拟机只要重新启动,IP地址便会跟着发生变化,这很是让人烦恼。

后来想着如何能让虚机IP固定下来呢,Google良久,终于有可固定的解决方式,下面请看详细解决步骤。

我本人的环境是,macOS版本是10.14.1VMware Fusion的版本是Professional Version 11.0.0 (10120384)

1. 查询虚拟机的MAC地址

话不多说,直接上图

设置-网络适配器

设置-网络是配置-MAC地址

2. 修改dhcpd.conf

dhcpd.conf位于目录/Library/Preferences/VMware Fusion/vmnet8。

用你最喜欢的文本编辑器打开/Library/Preferences/VMware Fusion/vmnet8/dhcpd.conf,我这里用vim,需要用管理员权限sudo,如下所示:
sudo vim /Library/Preferences/VMware\ Fusion/vmnet8/dhcpd.conf
看到的内容大概是这样:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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: 11/05/2018 15:38:24
allow unknown-clients;
default-lease-time 1800; # default is 30 minutes
max-lease-time 7200; # default is 2 hours

subnet 172.16.151.0 netmask 255.255.255.0 {
range 172.16.151.128 172.16.151.254;
option broadcast-address 172.16.151.255;
option domain-name-servers 172.16.151.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.151.2;
option routers 172.16.151.2;
}
host vmnet8 {
hardware ethernet 00:50:56:C0:00:08;
fixed-address 172.16.151.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" #######

host Ubuntu {
hardware ethernet 00:0C:29:F1:67:98;
fixed-address 172.16.151.188;
}

有三行内容值得注意:

  • 第1行,Ubuntu 是虚拟机的名字,看下图,注意要拼写要完全一致。

  • 第2行,00:0C:29:F1:67:98是上一步获取的MAC地址。

  • 第3行,192.168.110.130是要设置的固定IP地址,注意要在虚拟机的IP网段,一般情况下就用上次虚拟机运行时的动态IP就可以了。

3. 重启VMWare Fusion

必须重启VMWare Fusion才能使上边的设置生效。

4. 启动虚拟机

此时在启动虚拟机,你会发现虚拟机的地址不会再变来变去了,永远是你在步骤2设置的固定IP。