新面貌。新的 CentOS!
是的,CentOS 7 就是这么说的。
不管怎样,我最近在VMware上安装了CentOS 7,安装非常顺利。我尝试在安装后立即浏览网页,但无法执行此操作。
在进行一些基本的故障排除时,我注意到运行ifconfig时 IP 丢失。
[chandan@localhost ~]$ ifconfig
ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:0c:29:68:22:e2 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
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 0 (Local Loopback)
RX packets 642 bytes 55820 (54.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 642 bytes 55820 (54.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
[chandan@localhost ~]$你和我的情况一样吗?
本文提供了在使用 CentOS 7 的 VMware 上无法连接互联网的解决方案。
这可能表明网络适配器未启用或无法获取 DHCP IP 地址。
解决方案
- 接入终端/控制台
- 如果您还不是 root,请成为 root
- 运行
dhclient –v命令。 - 可以看到绑定的IP地址如下图。
[root@localhost network-scripts]# dhclient -v
Internet Systems Consortium DHCP Client 4.2.5 Copyright 2004-2013
Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/ Listening on LPF/ens32/00:0c:29:68:22:e2
Sending on LPF/ens32/00:0c:29:68:22:e2
Sending on Socket/fallback DHCPDISCOVER on ens32 to 255.255.255.255 port 67 interval 4 (xid=0x433a9e33) DHCPREQUEST on ens32 to 255.255.255.255 port 67 (xid=0x433a9e33)
DHCPOFFER from 172.16.179.254 DHCPACK from 172.16.179.254 (xid=0x433a9e33) bound to 172.16.179.136 -- renewal in 822 seconds.
[root@localhost network-scripts]#繁荣,就是这样。立即上网。当您运行ifconfig时,它还会查看 IP。
[root@localhost network-scripts]# ifconfig
ens32: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.179.136 netmask 255.255.255.0 broadcast 172.16.179.255
ether 00:0c:29:68:22:e2 txqueuelen 1000 (Ethernet)
RX packets 11 bytes 1255 (1.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 23 bytes 3536 (3.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 0 (Local Loopback)
RX packets 770 bytes 66956 (65.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 770 bytes 66956 (65.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0将其添加到自动启动
将其设置为自动启动意味着您不必每次启动 CentOS VM 时都执行此操作。
这就是将脚本设置为自动启动的方法,以便脚本在 VM 重新启动后自动启动。
- 转到/etc/init.d
- 创建以下文件。将名称保留为“ net-autostart ”。
#!/bin/bash
# Solution for "No Internet Connection from VMware"
#
### BEGIN INIT INFO
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
dhclient -v- 保存文件
- 将文件权限更改为可执行
chmod 755 net-autostart- 使用
chkconfig命令添加此脚本以进行自动启动
chkconfig --add net-autostart- 重启虚拟机并测试
我希望这有帮助。
如果您有兴趣学习 Linux 管理技能,请查看本课程。




![2021 年如何设置 Raspberry Pi Web 服务器 [指南]](https://i0.wp.com/pcmanabu.com/wp-content/uploads/2019/10/web-server-02-309x198.png?w=1200&resize=1200,0&ssl=1)

