修改源地址
sed 使用
查看修改后的效果(文件内容实际未修改)sed s/deb.debian.org/mirrors.aliyun.com/g /etc/apt/sources.list
添加 -i
参数,替换写入(文件内容修改)
sed -i s/deb.debian.org/mirrors.aliyun.com/g /etc/apt/sources.list
ubuntu
sed -i s/security.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list
sed -i s/archive.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list
sed -i s/cn.archive.ubuntu.com/mirrors.aliyun.com/g /etc/apt/sources.list
debian
sed -i s/deb.debian.org/mirrors.aliyun.com/g /etc/apt/sources.list
sed -i s/security.debian.org/mirrors.aliyun.com/g /etc/apt/sources.list
alpine
sed -i s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g /etc/apt/sources.list
修改 DNS
添加 DNS 服务器地址
echo 'nameserver 47.107.125.41' >> /etc/resolv.conf
替换原有地址
假设原来 DNS 服务器 127.0.0.11,查看目前 DNS 设置
cat /etc/resolv.conf
sed -i s/127.0.0.11/47.107.125.41/g /etc/resolv.conf
使用该 DNS,会将上述源地址重定向至阿里云镜像,不提供可用性保证
如果运行,出现类似错误? sed: can't move '/etc/resolv.conf73UqmG' to '/etc/resolv.conf': Device or resource busy
尝试下面命令
echo "$(sed 's/127.0.0.11/47.107.125.41/g' /etc/resolv.conf)" > /etc/resolv.conf
修改 hosts
支持的 HOSTS
# ubuntu
server_name archive.ubuntu.com;
server_name security.ubuntu.com;
server_name cn.archive.ubuntu.com;
# debian
server_name deb.debian.org;
server_name security.debian.org;
server_name prod.debian.map.fastly.net;
server_name debian.map.fastlydns.net;
# alpine
server_name dl-cdn.alpinelinux.org;
# mirrors
server_name mirrors.lidong.me;
server_name mirrors.oonnnoo.com;
server_name mirrors.ryanlid.net;
server_name mirrors.yidiankuaile.net;
更多
# ubuntu
echo '47.240.113.45 security.ubuntu.com' >> /etc/hosts
echo '47.240.113.45 archive.ubuntu.com' >> /etc/hosts
echo '47.240.113.45 cn.archive.ubuntu.com' >> /etc/hosts
# debian
echo '47.240.113.45 deb.debian.org' >> /etc/hosts
echo '47.240.113.45 security.debian.org' >> /etc/hosts
echo '47.240.113.45 prod.debian.map.fastly.net' >> /etc/hosts
echo '47.240.113.45 debian.map.fastlydns.net' >> /etc/hosts
# alpine
echo '47.240.113.45 dl-cdn.alpinelinux.org' >> /etc/hosts
sudo 执行
# ubuntu
sudo echo '47.240.113.45 security.ubuntu.com' >> /etc/hosts
sudo echo '47.240.113.45 archive.ubuntu.com' >> /etc/hosts
sudo echo '47.240.113.45 cn.archive.ubuntu.com' >> /etc/hosts
# debian
sudo echo '47.240.113.45 deb.debian.org' >> /etc/hosts
sudo echo '47.240.113.45 security.debian.org' >> /etc/hosts
sudo echo '47.240.113.45 debian.map.fastlydns.net' >> /etc/hosts
sudo echo '47.240.113.45 prod.debian.map.fastly.net' >> /etc/hosts
# alpine
sudo echo '47.240.113.45 dl-cdn.alpinelinux.org' >> /etc/hosts
如果运行 sudo echo x
出现 Permission denied
# hosts
sh -c "echo '47.240.113.45 security.ubuntu.com' >> /etc/hosts"
sh -c "echo '47.240.113.45 archive.ubuntu.com' >> /etc/hosts"
sh -c "echo '47.240.113.45 cn.archive.ubuntu.com' >> /etc/hosts"
sh -c "echo '47.240.113.45 dl-cdn.alpinelinux.org' >> /etc/hosts"
sh -c "echo '47.240.113.45 deb.debian.org' >> /etc/hosts"
sh -c "echo '47.240.113.45 security.debian.org' >> /etc/hosts"
sh -c "echo '47.240.113.45 debian.map.fastlydns.net' >> /etc/hosts"
sh -c "echo '47.240.113.45 prod.debian.map.fastly.net' >> /etc/hosts"
避免
sudo echo x >
时Permission denied
sudo 执行
# hosts
sudo sh -c "echo '47.240.113.45 security.ubuntu.com' >> /etc/hosts"
sudo sh -c "echo '47.240.113.45 archive.ubuntu.com' >> /etc/hosts"
sudo sh -c "echo '47.240.113.45 cn.archive.ubuntu.com' >> /etc/hosts"
sudo sh -c "echo '47.240.113.45 dl-cdn.alpinelinux.org' >> /etc/hosts"
sudo sh -c "echo '47.240.113.45 deb.debian.org' >> /etc/hosts"
sudo sh -c "echo '47.240.113.45 security.debian.org' >> /etc/hosts"
sudo sh -c "echo '47.240.113.45 debian.map.fastlydns.net' >> /etc/hosts"
sudo sh -c "echo '47.240.113.45 prod.debian.map.fastly.net' >> /etc/hosts"