网站节点加速,中国各大网站排名,重庆建网站推广公司,网站彩铃怎么做的事情发生在两天前#xff0c;位于公网的阿里云轻量级服务器#xff08;Ubuntu 24.04.1 LTS#xff09;忽然没网。主要是上次上服务器进行配置已经是一个多月前#xff0c;最近也没有做什么事情#xff0c;就忽然没网了#xff0c;让人纳闷。更主要的是#xff0c;上次备…事情发生在两天前位于公网的阿里云轻量级服务器Ubuntu 24.04.1 LTS忽然没网。主要是上次上服务器进行配置已经是一个多月前最近也没有做什么事情就忽然没网了让人纳闷。更主要的是上次备份是一个多月前如果回滚最近一个月上传的数据将会丢失。最后花了三个小时终于解决了问题。
一、故障现象
在当前故障状态下打了个备份回滚到上一次可以联网的状态进行分析。对比发现主要有以下几个故障现象。
一ping 不通
发现在自己电脑尝试使用 ssh、https 等协议访问服务器不同的端口都无法访问ping 也 ping 不进去。在阿里云救援连接下执行 ping www.baidu.com 不通执行 ping 8.8.8.8 也不通。感觉就是完全没网。
二执行 ifconfig 只有 lo 没有 eth0
回滚了一下以前的版本发现可以联网执行 ifconfig显示如下具体 IP 地址用 X 进行了代替。
rootUniverse:~# ifconfig
eth0: flags4163UP,BROADCAST,RUNNING,MULTICAST mtu 1500inet XXX.XXX.XXX.XXX netmask XXX.XXX.XXX.XXX broadcast XXX.XXX.XXX.XXXinet6 XXXX:XXXX:XXXX:XXXX:XXXX prefixlen 64 scopeid 0x20linkether 00:16:3e:0c:12:69 txqueuelen 1000 (Ethernet)RX packets 1759 bytes 194870 (194.8 KB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 1826 bytes 1352244 (1.3 MB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags73UP,LOOPBACK,RUNNING mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10hostloop txqueuelen 1000 (Local Loopback)RX packets 332540 bytes 27292720 (27.2 MB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 332540 bytes 27292720 (27.2 MB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0在当前故障状态下执行 ifconfig显示如下没有 eth0。
rootUniverse:~# ifconfig
lo: flags73UP,LOOPBACK,RUNNING mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10hostloop txqueuelen 1000 (Local Loopback)RX packets 332540 bytes 27292720 (27.2 MB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 332540 bytes 27292720 (27.2 MB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0三执行 route -n 没有任何信息
回滚到可以联网的版本时执行 route -n 是有数据的用 X 替换了真实 IP。
rootUniverse:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 XXX.XXX.XXX.XXX 0.0.0.0 UG 100 0 0 eth0
XXX.XXX.XXX.XXX XXX.XXX.XXX.XXX 255.255.255.255 UGH 100 0 0 eth0
XXX.XXX.XXX.XXX XXX.XXX.XXX.XXX 255.255.255.255 UGH 100 0 0 eth0
XXX.XXX.XXX.XXX 0.0.0.0 255.255.192.0 U 100 0 0 eth0
XXX.XXX.XXX.XXX 0.0.0.0 255.255.255.255 UH 100 0 0 eth0故障状态下执行 route -n没有有效数据。
rootUniverse:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface(四阿里云控制台诊断未发现异常 二、分析与尝试
一从 ping 下手
如果只是 ping www.baidu.com 失败而 ping 8.8.8.8 成功那应该是 DNS 问题解决这个问题网上教程有很多。但是根据故障现象一可以知道连 8.8.8.8 都 ping 不通那肯定不只是 DNS 的问题。笔者也试了一下当成 DNS 问题进行解决但服务器依旧无法连接上。 百度和谷歌搜索 ping temporary failure in name resolution 和 ping connect network is unreachable 了半天说要修改 /etc/resolv.conf添加 8.8.8.8 和 8.8.4.4但对比了一下之前正常联网的文件发现该文件没有变化所以应该不用修改。事实上笔者尝试过修改无济于事。
rootUniverse:~# cat /etc/resolv.conf
# This is /run/systemd/resolve/stub-resolv.conf managed by man:systemd-resolved(8).
# Do not edit.
#
# This file might be symlinked as /etc/resolv.conf. If youre looking at
# /etc/resolv.conf and seeing this text, you have followed the symlink.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run resolvectl status to see details about the uplink DNS servers
# currently in use.
#
# Third party programs should typically not access this file directly, but only
# through the symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a
# different way, replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.nameserver 127.0.0.53
options edns0 trust-ad
search .二搜索其它相关解决方案可能对其它网络问题有用可逐个尝试
修改 /etc/sysconfig/network-script 下的配置文件发现 cd 到这个目录时提示目录不存在使用 Network-Manager、networkmanger、nmcli、netset 等工具和 service XXX restart 等命令重启网络管理器均提示不存在或服务未安装检查发现正常状态下也没有装过这些东西所以尝试 apt 安装想啥呢没网啊使用 /etc/init.d/networking提示没有这个文件怎么什么都没有见得最多的是 /etc/network/interfacescd 过去哦吼又没有这个文件夹GPT 说从 Ubuntu 17 开始/etc/network/interfaces 变成了 netplan比较了下故障状态下和正常状态下的配置发现 /etc/netplan 下多了个 yaml 文件于是删除了多余的 yaml 文件只留下了 50-cloud-init.yaml不过还是不行但这个更改还是做了吧毕竟和以前正常状态下的保持一致一般没错设置默认网关主要是笔者在当前阶段执行 ifconfig 连 eth0 都没有所以执行 route add default gw 自然失败但这最后助攻了一手。
(三从 ifconfig 执行
既然没有 eth0那就执行 ipconfig eth0 up。启动 eth0 网卡后再次执行 ifconfig有 eth0 了但是没有 inet显示如下。
rootUniverse:~# ifconfig
eth0: flags4163UP,BROADCAST,RUNNING,MULTICAST mtu 1500inet6 XXXX:XXXX:XXXX:XXXX:XXXX prefixlen 64 scopeid 0x20linkether 00:16:3e:0c:12:69 txqueuelen 1000 (Ethernet)RX packets 1759 bytes 194870 (194.8 KB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 1826 bytes 1352244 (1.3 MB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags73UP,LOOPBACK,RUNNING mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10hostloop txqueuelen 1000 (Local Loopback)RX packets 332540 bytes 27292720 (27.2 MB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 332540 bytes 27292720 (27.2 MB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0于是根据之前的地址执行了 ifconfig eth0 XXX.XXX.XXX.XXX netmask XXX.XXX.XXX.XXX。再次执行 ifconfig发现除了 RX 和 TX 之外故障状态下和正常联网状态下的输出没有什么不同。感觉 eth0 转发的数据应该要比 lo 的多得多而故障状态下的服务器并非如此于是尝试在谷歌和百度上搜索这个问题没搜索到结果可能是表达问题。最后想了想应该是要把默认网卡切为 eth0依照此思路执行了 route add default gw XXX.XXX.XXX.XXX eth0这里的 XXX.XXX.XXX.XXX 对应上文 gateway 下面的地址。忽然一切问题得到了解决。
解决方案
执行 ifconfig eth0 up 把网关启用回来然后执行 ifconfig eth0 XXX.XXX.XXX.XXX netmask XXX.XXX.XXX.XXX 把网卡 eth0 加回来最后用 route add default gw XXX.XXX.XXX.XXX eth0 设置默认网关结束。