Centos

CentOS 失去網際網路連接

  • March 26, 2019

我已經配置了 CentOS VM,禁用了 NetworkManager。

問題:

當我啟動虛擬機時,我可以訪問網際網路,但過了一段時間我失去了它。我該如何解決?

在第一步中,您說:

當我啟動虛擬機時,我可以訪問網際網路,但過了一段時間我失去了它:

在控制台上測試這個:

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.

然後執行此命令以顯示您的 IP:

ip addr or ifconfig

那麼你應該添加到啟動自動/啟動:轉到:cd /etc/init.d

使用 sudo vim 創建 net-autostart 文件並保存:

#!/bin/bash
# Solution for "Centos Connection from VMware"
#
### BEGIN INIT INFO
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
dhclient -v

執行命令:

chmode +755 net-autostart

chconfig --add net-autostart

重啟虛擬機

引用自:https://unix.stackexchange.com/questions/508492