VMware虚拟机安装详细教程网络NAT、网桥配置
时间:2023-11-20 23:37:01
VMware16 安装准备
虚拟机下载安装:
VMware Workstation Pro 16
CentOS镜像下载安装:
建议选择国内镜像源:
阿里云镜像:https://mirrors.aliyun.com/centos/
网易开源镜像:https://mirrors.163.com/centos/
CentOS选择版本:CentOS 7.9
进入镜像源网页后,参考上述路径找到图中显示的镜像并下载。上述镜像版本的区别:
- CentOS ISO:DVD是标准安装板,一般可以下载这个,包含大量常用软件,大多数情况下安装不需要在线下载,体积4G;
- Minimal ISO:包含核心组件的精简版;
- Everything ISO:顾名思义,它包含了所有的软件组件,当然体积也很大,高达7G。补充完整版安装板的软件,整合所有软件。
安装步骤
配置虚拟机操作系统
- 创建新的虚拟机 -> 典型 -> 下一步
- 安装客户机操作系统 -> 稍后安装操作系统 -> 下一步
- 选择客户机操作系统 -> Linux CentOS 7 64 位 -> 下一步
- 命名虚拟机 -> 按需配置 -> 下一步
![]https://img-blog.csdnimg.cn/img_convert/921c6bd34edc8b387a21f10e3b7de23f.png()
- 指定磁盘容量 -> 保持默认或按需配置 -> 下一步
- 硬件:
- 内存:按需配置
- 处理器:按需配置
- 网络适配器:默认
- 关闭 -> 完成
安装虚拟机操作系统
- 选择自己刚才配置的虚拟机 -> 打开虚拟机,进入安装步骤
- 安装(如果下面有弹出窗口,直接关闭,然后 选择Install CenOS 7.等待安装)
- 选择安装语言(下面弹窗选后两项关掉即可)
- 摘要安装信息 -> 安装位置 -> 完成 -> 开始安装
- 配置 Root 账号和密码不需要在这里创建用户
- 完成配置 -> 重启
配置NAT网络
- 查看网络信息 -> 编辑 -> 虚拟网络编辑器 -> 记住子网 IP 的前三段
- 配置虚拟主机
登录虚机 root 账号和密码
修改 ifcfg-ens32 文件内容如下:
-
TYPE:以太网
-
BOOTPROTO:static 静态 IP
-
NAME 和 DEVICE:文件名和计算机名
-
ONBOOT:启动网络
-
IPADDR:IP地址(前三段应与步骤1中的前三段一致,第四段可设置 1-255 中任意值)
-
NETMASK:子网掩码(固定的 255.255.255.0)
-
GATEWAY:网关(前三段与步骤一中前三段一致 4 段为 2)
-
DNS:域名解析器
- 192.168.83.2.自己的网关
- 114.114.114.114:中国联通、移动、电信
- 8.8.8.8:谷歌的
修改后,重启网络并进行测试:
重启网络
systemctl restart network
测试
ping baidu.com
桥接模式网络的配置
网络配置
vi /etc/sysconfig/network-scripts/ifcfg-ensxxx
详细配置(区分大小写):
##修改BOOTPROTO="static" # 配置成静态IP ONBOOT="yes" # 是否从网络服务开始 ##新增 IPADDR="192.168.1.103" #主机ip地址 GATEWAY="192.168.1.1" # 网关 NETMASK="255.255.255.0" # 子网掩码 DNS1="8.8.8.8" #DNS
重启网络服务
systemctl restart network
配置防火墙
#检查防火墙开口端口 firewall-cmd --list-ports #开放防火墙端口 firewall-cmd --zone=public --add-port=8080/tcp --permanent #修改重载配置 firewall-cmd --reload #检查防火墙的状态 firewall-cmd --state #打开防火墙 systemctl start firewalld #关闭防火墙 systemctl stop firewalld #禁止firewall开机启动 systemctl disable firewalld
测试
- 内网访问自身静态ip
[root@localhost Desktop]# ping 192.168.0.200 PING 192.168.0.200 (192.168.0.200) 56(84) bytes of data. 64 bytes from 192.168.0.200: icmp_seq=1 ttl=64 time=0.036 ms 64 bytes from 192.168.0.200: icmp_seq=2 ttl=64 time=0.043 ms 64 bytes from 192.168.0.200: icmp_seq=3 ttl=64 time=0.047 ms 64 bytes from 192.168.0.200: icmp_seq=4 ttl=64 time=0.046 ms ^C --- 192.168.0.200 ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 2999ms rtt min/avg/max/mdev = 0.036/0.043/0.047/0.004 ms
-
访问公网
[root@localhost Desktop]# ping www.baidu.com PING www.a.shifen.com (180.97.33.108) 56(84) bytes of data. 64 bytes from 180.97.33.108: icmp_seq=1 ttl=57 time=2.52 ms 64 bytes from 180.97.33.108: icmp_seq=2 ttl=57 time=2.4 ms 64 bytes from 180.97.33.108: icmp_seq=3 ttl=57 time=3.20 ms 64 bytes from 180.97.33.108: icmp_seq=4 ttl=57 time=2.20 ms 64 bytes from 180.97.33.108: icmp_seq=5 ttl=57 time=3.56 ms 64 bytes from 180.97.33.108: icmp_seq=6 ttl=57 time=2.08 ms 64 bytes from 180.97.33.108: icmp_seq=7 ttl=57 time=2.11 ms 64 bytes from 180.97.33.108: icmp_seq=8 ttl=57 time=2.37 ms 64 bytes from 180.97.33.108: icmp_seq=9 ttl=57 time=2.58 ms 64 bytes from 180.97.33.108: icmp_seq=10 ttl=57 time=3.61 ms 64 bytes from 180.97.33.108: icmp_seq=11 ttl=57 time=3.74 ms 64 bytes from 180.97.33.108: icmp_seq=12 ttl=57 time=2.81 ms ^C --- www.a.shifen.com ping statistics --- 12 packets transmitted, 12 received, 0% packet loss, time 11021ms rtt min/avg/max/mdev = 2.047/2.738/3.744/0.609 ms
-
宿主机访问虚拟机
C:\Users\Administrator\Desktop ping 192.168.0.200 正在 Ping 192.168.0.200 具有 32 字节的数据: 来自 192.168.0.200 的回复: 字节=32 时间<1ms TTL=64 来自 192.168.0.200 的回复: 字节=32 时间<1ms TTL=64 来自 192.168.0.200 的回复: 字节=32 时间<1ms TTL=64 来自 192.168.0.200 的回复: 字节=32 时间<1ms TTL=64 192.168.0.200 的 Ping 统计信息: 数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失), 往返行程的估计时间(以毫秒为单位): 最短 = 0ms,最长 = 0ms,平均 = 0ms
- 虚拟机访问宿主机
[root@localhost Desktop]# ping 192.168.0.107 PING 192.168.0.107 (192.168.0.107) 56(84) bytes of data. 64 bytes from 192.168.0.107: icmp_seq=1 ttl=128 time=0.487 ms 64 bytes from 192.168.0.107: icmp_seq=2 ttl=128 time=0.408 ms 64 bytes from 192.168.0.107: icmp_seq=3 ttl=128 time=0.394 ms 64 bytes from 192.168.0.107: icmp_seq=4 ttl=128 time=0.362 ms 64 bytes from 192.168.0.107: icmp_seq=5 ttl=128 time=0.401 ms 64 bytes from 192.168.0.107: icmp_seq=6 ttl=128 time=0.398 ms 64 bytes from 192.168.0.107: icmp_seq=7 ttl=128 time=0.434 ms ^C --- 192.168.0.107 ping statistics --- 7 packets transmitted, 7 received, 0% packet loss, time 6005ms rtt min/avg/max/mdev = 0.362/0.412/0.487/0.036 ms
如果无法ping通上网可能需要选择以下网卡:
-
VMware菜单栏->编辑->虚拟网络编辑器
做一下切换,保存试试,这一步十分重要,如果出现的画面没有VMnet0, 可能是因为权限不够,右下角点击更改设置即可
VMware虚拟网卡的说明:
网络类型 网络适配器名
Bridged VMnet0
NAT VMnet8
Host-only VMnet1
Linux yum 命令详解 源配置