Ubuntu 20.04.6 LTS执行sudo apt update时出现网络连接错误求助
Ubuntu 20.04.6 LTS执行sudo apt update时出现网络连接错误求助
你好,我看到你在PowerEdge R230服务器上安装Ubuntu 20.04.6 LTS后,运行sudo apt update时遇到了网络连接失败的问题,具体报错如下:
Cannot initiate the connection to it.archive.ubuntu.com:80 (2001:760:ffff:b6:4:100:0:70). - connect (101: Network is unreachable) Cannot initiate the connection to it.archive.ubuntu.com:80 (2001:760:ffff:b6:4:100:0:72). - connect (101: Network is unreachable) Cannot initiate the connection to it.archive.ubuntu.com:80 (2001:760:ffff:b6:4:100:0:73). - connect (101: Network is unreachable) Could not connect to it.archive.ubuntu.com:80 (90.147.160.73), connection timed out Could not connect to it.archive.ubuntu.com:80 (90.147.160.70), connection timed out Could not connect to it.archive.ubuntu.com:80 (90.147.160.72), connection timed out Err:2 http://it.archive.ubuntu.com/ubuntu focal-updates InRelease Cannot initiate the connection to it.archive.ubuntu.com:80 (2001:760:ffff:b6:4:100:0:70). - connect (101: Network is unreachable)
针对这个问题,我整理了几个实用的解决思路,你可以逐一尝试:
1. 临时禁用IPv6测试连接
从报错信息来看,系统首先尝试通过IPv6地址连接软件源但失败了(提示Network is unreachable),大概率是你的网络环境不支持IPv6,或者系统IPv6配置异常。可以先临时禁用IPv6试试:
- 执行以下命令临时关闭IPv6:
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1 sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1 - 之后再运行
sudo apt update,如果能正常更新,说明是IPv6的问题。想要永久禁用的话,编辑/etc/sysctl.conf文件:
在文件末尾添加两行:sudo nano /etc/sysctl.conf
保存退出(按net.ipv6.conf.all.disable_ipv6=1 net.ipv6.conf.default.disable_ipv6=1Ctrl+O回车,再Ctrl+X),最后执行sudo sysctl -p让配置生效。
2. 更换为国内稳定的软件源
意大利官方源(it.archive.ubuntu.com)可能因为网络距离太远导致连接超时,换成国内的镜像源比如阿里云源会更稳定:
- 先备份原来的源配置文件,防止出错:
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak - 编辑源文件:
sudo nano /etc/apt/sources.list - 把文件里的内容全部替换成阿里云的focal版本源:
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse - 保存退出后,运行
sudo apt update测试是否正常。
3. 检查服务器基础网络配置
如果上面两个方法都没用,那可能是服务器本身的网络配置有问题:
- 先测试基础网络连通性:运行
ping 8.8.8.8,如果能收到回复,说明网络链路没问题;如果ping不通,需要检查网卡配置。 - 查看Netplan配置文件(Ubuntu 20.04用Netplan管理网络):进入
/etc/netplan目录,查看里面的.yaml配置文件,确认IP地址、网关、DNS服务器是否和你的网络环境匹配。
备注:内容来源于stack exchange,提问作者Carburio
相关产品推荐
相关产品推荐

