Mac 下使用 VMware Fusion ,安装 Centos7,并且配置静态 IP 上网。
安装过程省略,网上教程很多。安装完毕后,接下来配置网络NAT 模式上网。一般情况下默认就是 NAT 模式,如果不是的话,点击窗口上方的按钮设置为 NAT 模式。同时将网络适配器设置为”与我的 Mac 共享”。

进入 VM 的配置文件目录,/Library/Preferences/VMware Fusion/vmnet8
1 2
| ➜ vmnet8 ls dhcpd.conf dhcpd.conf.bak nat.conf nat.conf.bak nat.mac
|
查看 nat.conf 配置文件,可以得到 gateway ip和 netmask后面需要用到。
1 2 3 4 5 6 7 8 9
| ➜ vmnet8 cat nat.conf [host]
useMacosVmnetVirtApi = 1
ip = 172.16.127.1 netmask = 255.255.255.0
|
然后登录虚拟机,进入网卡配置目录
1 2 3 4
| [root@localhost ~] [root@localhost network-scripts] ifcfg-ens33 ifdown-isdn ifdown-tunnel ifup-isdn ifup-Team ......
|
修改 ifcfg-ens33 如下所示:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=static //修改为 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=9cd8fc87-2d21-48a3-9546-4a7788889dd8 DEVICE=ens33 ONBOOT=yes // 自启动 IPADDR=172.16.127.3 // 除了172.16.127.1 外,172.16.127.x 一般都可以 GATEWAY=172.16.127.1 // 上面查询到的 NETMASK=255.255.255.0 // 上面查询到的
|
[root@localhost network-scripts]# ifconfig
-bash: ifconfig: 未找到命令
查看下网络配置,因为缺少工具,net-tools.x86_64
。网络配置完毕后,可以 yum 安装下
然后重启网络即可
1 2
| [root@localhost network-scripts] Restarting network (via systemctl): [ 确定 ]
|
测试下:
1 2 3 4 5
| [root@localhost network-scripts] PING baidu.com (220.181.38.251) 56(84) bytes of data. 64 bytes from 220.181.38.251 (220.181.38.251): icmp_seq=1 ttl=42 time=16.1 ms 64 bytes from 220.181.38.251 (220.181.38.251): icmp_seq=2 ttl=42 time=14.6 ms .....
|
安装工具net-tools.x86_64。
1 2 3 4 5 6 7 8 9 10 11 12 13
| [root@localhost network-scripts] .....
[root@localhost network-scripts] ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 172.16.127.3 netmask 255.255.255.0 broadcast 172.16.127.255 inet6 fd15:4ba5:5a2b:1008:7edf:f1ba:f599:7352 prefixlen 64 scopeid 0x0<global> inet6 fe80::e86:bbff:8ea0:8b prefixlen 64 scopeid 0x20<link> ether 00:0c:29:3d:1c:e1 txqueuelen 1000 (Ethernet) RX packets 53537 bytes 30257363 (28.8 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 42318 bytes 5227531 (4.9 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
|
ssh工具连接,如果连接失败,一定是防火墙开着,放开端口或者关闭防火墙即可。