VMware Workstation 17.5.1 网络故障排查:解决 NAT 模式无法访问外网问题

问题描述

在虚拟机中版本VMware 17.5.1,linux环境centos7.9 使用的是NAT方式,连接不到外网的解决方案,原因是网络服务冲突,CentOS 7 开始从传统的 network 服务向 NetworkManager 过渡 ,传统 network 服务NetworkManager 服务 同时运行,导致资源竞争,在较新的 CentOS 8/9 中,已经完全转向 NetworkManager,这种问题就很少见了。

之前能ping通外部网络的都有ens33网络模块,会有一个局域网的ip,类似于192.168.31.143这样的ip模块,这个不存在。

bash 复制代码
[stark@localhost ~]$ ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:a3:0e:0f  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

解决步骤

1、清理冲突进程

停止了所有可能冲突的服务和进程,为重新配置提供了干净的环境

bash 复制代码
sudo systemctl stop NetworkManager
sudo systemctl stop network
sudo pkill dhclient

2、重置接口状态

清除了可能存在的旧 IP 配置,重置了网络接口的软件状态

bash 复制代码
sudo ip addr flush dev ens33
sudo ip link set dev ens33 down

3、检查网络配置文件

bash 复制代码
sudo cat /etc/sysconfig/network-scripts/ifcfg-ens33
//确保内容如下:
TYPE=Ethernet
BOOTPROTO=dhcp
NAME=ens33
DEVICE=ens33
ONBOOT=yes

4、重启网络服务

bash 复制代码
# 先启动 NetworkManager
sudo systemctl start NetworkManager

# 等待几秒后启动 network 服务
sudo systemctl start network

5、如果仍然失败,使用 NetworkManager 直接管理

bash 复制代码
# 禁用传统的 network 服务
sudo systemctl disable network

# 启用 NetworkManager
sudo systemctl enable NetworkManager
sudo systemctl start NetworkManager

# 使用 nmcli 配置网络
sudo nmcli connection delete ens33 2>/dev/null
sudo nmcli connection add type ethernet con-name ens33 ifname ens33
sudo nmcli connection up ens33

6、手动获取 IP 地址

bash 复制代码
# 启用网络接口
sudo ip link set ens33 up

# 强制释放并重新获取 IP
sudo dhclient -r ens33
sudo dhclient -v ens33

# 检查是否获取到 IP
ip addr show ens33

7、验证

bash 复制代码
[stark@localhost ~]$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.31.143  netmask 255.255.255.0  broadcast 192.168.31.255
        inet6 fe80::20c:29ff:fe78:2946  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:78:29:46  txqueuelen 1000  (Ethernet)
        RX packets 147  bytes 27275 (26.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 27  bytes 4553 (4.4 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:a3:0e:0f  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

至此,完美解决了VMware 不能访问外网的问题!

相关推荐
如意.7598 小时前
【Linux开发工具实战】Git、GDB与CGDB从入门到精通
linux·运维·git
Thera7779 小时前
C++ 高性能时间轮定时器:从单例设计到 Linux timerfd 深度优化
linux·开发语言·c++
爱吃土豆的马铃薯ㅤㅤㅤㅤㅤㅤㅤㅤㅤ10 小时前
Linux 查询某进程文件所在路径 命令
linux·运维·服务器
安当加密11 小时前
无需改 PAM!轻量级 RADIUS + ASP身份认证系统 实现 Linux 登录双因子认证
linux·运维·服务器
内卷焦虑人士12 小时前
Windows安装WSL2+Ubuntu 22.04
linux·windows·ubuntu
耗子会飞13 小时前
小白学习固定VM虚拟机的centos服务器的IP
运维·服务器·centos
dddddppppp12313 小时前
qemu模拟的一个内核驱动 io口中断
linux
程序员老赵13 小时前
超全 Docker 镜像源配置指南|Windows/Mac/Linux一键搞定,拉镜像再也不卡顿
linux·后端·容器
门豪杰14 小时前
Ubuntu下安装Claude Code
linux·运维·ubuntu·claude·claude code
总要冲动一次14 小时前
离线安装 percona-xtrabackup-24
linux·数据库·mysql·centos