设置vmware虚拟机固定IP

最近在mac上用vmware fusion,但是经常有这样一个问题。就是换一个局域网,虚拟机上的guest OSubuntu/Centos等)就会断开网络然后重新换成一个新的IP,弄得我很麻烦,每换一个局域网都需要手动重新设置一下,来和新的IP相适应。后来终于发现了一个可以在mac上把虚拟机IP固定的方法,本机更换局域网不会对guest OSIP有任何影响,在此分享给大家,希望大家能够不再被这个问题困扰。


这是mac上的解决方法,windows上可能会有一些小的改动。

只需要打开终端,输入sudo -s切换到root身份,然后打开配置文件:

MacBook-Pro-2:vim baidu$ sudo -s
Password:
bash-3.2# vim /Library/Preferences/VMware\ Fusion/vmnet8/dhcpd.conf

文件内容如下:

# 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/01/2016 19:07:47
allow unknown-clients;
default-lease-time 1800;                # default is 30 minutes
max-lease-time 7200;                    # default is 2 hours

subnet 192.168.39.0 netmask 255.255.255.0 {
	range 192.168.39.128 192.168.39.254;
	option broadcast-address 192.168.39.255;
	option domain-name-servers 192.168.39.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.39.2;
	option routers 192.168.39.2;
}
host vmnet8 {
	hardware ethernet 00:50:56:C0:00:08;
	fixed-address 192.168.39.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:50:56:3B:11:26;
	fixed-address 192.168.39.151;
}

在最后边添加以下内容即可

host ubuntu {

hardware ethernet 00:50:56:3B:11:26;

fixed-address 192.168.39.151;

}

host后边的内容是你虚拟机上显示的名字,网卡地址自己打开虚拟机设置上边可以看到,fixed-address就是你想要设置的Ip,但是记住,一定要在你虚拟机的dhcp网段内,我的vmware采用的NAT模式,dhcp网段是192.168.39.1-192.168.39.255修改完以后,重启vmware就可以啦。

你可能感兴趣的:(其他)