抱歉,您的浏览器无法访问本站

本页面需要浏览器支持(启用)JavaScript


了解详情 >

Mac的VM中设置虚拟机静态ip

闲来无事,想学习下spark相关的知识,于是需要几台服务器,无奈囊中羞涩双十一都买不起一台服务器,只能借助2015款的mac pro帮助虚拟几台服务器来暂时用用。

准备过程

FinalShell 一款国产的mac上可用的shell命令工具
VMware Fusion mac上用来安装虚拟机的工具
centos7 的最简版镜像

设置VMware Fusion

第一步:修改vmware 配置网卡的配置文件

只更改Vnet8 的网卡

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ vim /Library/Preferences/VMware\ Fusion/networking

VERSION=1,0
answer VNET_1_DHCP yes
answer VNET_1_DHCP_CFG_HASH EC13F23285B5086AFF5BDFFA85E8DE0338C2AF74
answer VNET_1_HOSTONLY_NETMASK 255.255.255.0
answer VNET_1_HOSTONLY_SUBNET 172.16.208.0
answer VNET_1_VIRTUAL_ADAPTER yes
#关闭dhcp
answer VNET_8_DHCP no
answer VNET_8_DHCP_CFG_HASH 13FB4A1FC14575A20209A2C7C8C2E5EED98C6665
# 子网掩码
answer VNET_8_HOSTONLY_NETMASK 255.255.255.0
#设置ip段
answer VNET_8_HOSTONLY_SUBNET 192.168.100.0
answer VNET_8_NAT yes
answer VNET_8_VIRTUAL_ADAPTER yes
# vmnet8 的IP
answer VNET_8_VIRTUAL_ADAPTER_ADDR 192.168.100.1

第二步:设置网关

1
2
3
4
5
6
7
#配置nat.conf 这个文件
vim /Library/Preferences/VMware\ Fusion/vmnet8/nat.conf

#设定nat网管和子网
# NAT gateway address
ip = 192.168.100.2
netmask = 255.255.255.0

第三步: 重启vmnet8网卡

1
2
3
4
5
6
7
# 查看网卡状态
$ sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --status
# 关闭网卡
$ sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --stop

# 启动网卡
$ sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --start

~~~~
中间省去在vm中创建centos的虚拟机步骤
~~~~

第四步:设置centos网卡

1、配置网卡
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
 $ vi /etc/sysconfig/network-scripts/ifcfg-ens33 

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
# 设置静态的ip,而不是dhcp方式
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=74ad3dd0-742d-422b-b165-6f0d0b6e2f6d
DEVICE=ens33
# 设置网卡开机启动
ONBOOT=yes
# 设置当前centos的ip地址
IPADDR=192.168.100.15
# 设置网关
GATEWAY=192.168.100.2
# 设置子网掩码
NETMASK=255.255.255.0
#设置dns
DNS1=119.29.29.29
DNS2=182.254.116.116

2、重启centos网卡
1
2
3
4
5
6
#重启网卡
systemctl restart network

# 查看网卡
ip addr

2、测试
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:dd:bc:55 brd ff:ff:ff:ff:ff:ff
inet 192.168.100.15/24 brd 192.168.100.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet6 fe80::a3c4:b923:6d37:e7aa/64 scope link tentative noprefixroute dadfailed
valid_lft forever preferred_lft forever
inet6 fe80::3427:d5be:210e:dce2/64 scope link tentative noprefixroute dadfailed
valid_lft forever preferred_lft forever
inet6 fe80::3f6a:22ae:8bdd:e0ac/64 scope link noprefixroute
valid_lft forever preferred_lft forever

测试发现ens33的ip地址已经变成了我们设置的ip了.

测试访问外网

1
2
3
4
5
6
7
8
9
10
11
$ 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=128 time=17.9 ms
64 bytes from 180.101.49.12 (180.101.49.12): icmp_seq=2 ttl=128 time=117 ms
64 bytes from 180.101.49.12 (180.101.49.12): icmp_seq=4 ttl=128 time=26.7 ms
^C
--- www.a.shifen.com ping statistics ---
4 packets transmitted, 3 received, 25% packet loss, time 3004ms
rtt min/avg/max/mdev = 17.996/54.184/117.813/45.134 ms

大工告成,开始happy!!!

评论