本文讲述了在VMware Workstation中CentOS7虚拟机与宿主机间的网络配置与通信,不涉及原理知识,只是简单的操作。
1.虚拟机安装
从官网下载CentOS 7 minimal 版本的镜像,完成安装虚拟机。
##### 2.VMware网络配置 2.1 在VMware的Home页面点击“编辑—>虚拟网络编辑器”可打开虚拟网络编辑窗口,如下图

2.2 我们选择VMnet8,然后点击NAT设置。

这里我们要记下子网IP和网关IP,等会儿会用到。
##### 3.配置虚拟机网卡 3.1 接下来去配置虚拟机网卡,在网络连接里面,右键点击VMware Network Adapter VMnet8,再点击属性


3.2 选择设置IPv4属性->使用下面的IP地址:
1.IP地址对应刚才的子网IP,最后一位改为1.
2.子网掩码对应刚才的255.255.255.0
3.默认网关对应刚才的网关IP

##### 4.配置虚拟机IP 4.1 用root账户登录虚拟机,进入到 **/etc/sysconfig/network-scripts/**目录下
cd /etc/sysconfig/network-scripts/

4.2 编辑ifcfg-ens33
vi ifcfg-ens33
4.3 添加或修改相关语句
1 | TYPE=Ethernet |
这里的UUID和IPADDR要格外留意,后期克隆虚拟机的时候要修改
保存退出
4.4 重启网络服务
systemctl restart network
4.5 关闭防火墙
systemctl stop firewalld service
##### 5.检查虚拟机和宿主机间的通信 > ping 192.168.204.1

##### 6.修改hosts文件,通过主机名进行通信 6.1 编辑/etc/hosts文件,添加IP地址和主机名
1 | 192.168.204.1 victor |
这样就能通过主机名代替IP地址来进行通信了。