注意
本次教程需要熟悉简单的vim命令,具体vim使用教程查看教程Linux系列二之Linux入门简介
一、VMware虚拟机NAT模式联网原理图
虚拟机在NAT模式时会虚拟出一个内网,主机和虚拟机都在这个虚拟的局域网中。NAT中VMWare相当于交换机(产生一个局域网,在这个局域网中分别给主机和虚拟机分配ip地址)


第一步、VMware网关设置





第二步、windows电脑虚拟网卡VMware Virtual Ethernet Adapter for VMnet8设置



第三步、Centos虚拟机设置
3-1、修改IP地址
vim /etc/sysconfig/network-scripts/ifcfg-eno16777736

3-2、修改hostname
hostnamectl set-hostname docker200

3-3、修改hostname和主机的映射
vim /etc/hosts

3-4、修改前三项完毕后重启虚拟机
# 重启
reboot -f

3-5、测试虚拟机是否可以联网(首先要确保你的windows电脑可以联网)
3.5.1测试 windows电脑 是否可以联网

3.5.2测试虚拟机是否可以与网关通信

3.5.3测试虚拟机是否可以联网
ping www.baidu.com

至此虚拟机NAT模式联网设置已经完毕,为方便操作Linux,我们一般都是使用第三方软件连接虚拟机。以下是连接相关设置。
第四步、使用Xshell连接Centos虚拟机(选做)
软件准备
- Xshell5
Xshell软件安装教程自行百度。
4-1、修改windows电脑IP和主机映射(可以不修改,主要是连接时不用写IP比较方便)
为了方便windows电脑上面使用Xshell连接Centos虚拟机,可以在windows电脑上设置主机名和IP的映射
找到 c:/windows/system32/drivers/etc/hosts文件,添加IP地址和主机名的映射

4-2、使用Xshell连接虚拟机


连接成功

网友评论