n3wFake3

Configure Apt Proxy

设置apt Acquire配置项,让你不再为apt不走代理而烦恼

使用Ubuntu Desktop也有一段时间了,在国内环境,如果需要顺畅更新软件包,就需要使用国内镜像,例如阿里云,163。但是国内镜像源又需要经常同步Ubuntu官方源,没有同步完成的时候更新包会出现file hash not match等问题,故此我决定使用Ubuntu官方源

但是使用官方源有一个问题就是网络环境不通畅,且apt是不走all_proxy/http[s]_proxy代理的,苦苦寻找一番,终于找到解决方法。

解决方法

# 先确认 /etc/apt/ 目录下是否有apt.conf文件
cat /etc/apt/apt.conf || sudo touch /etc/apt/apt.conf

# 以下配置按照我本地clash进行设置
# 且必须带有 http://
cat <<CONF | sudo tee /etc/apt/apt.conf
Acquire::Http::Proxy "http://127.0.0.1:7890";
Acquire::Https::Proxy "http://127.0.0.1:7890";
CONF

完成设置后,进行update并查看clash日志检查是否命中代理规则

sudo apt-get update
# ...
7月 29 23:46:48 ubuntu-X550JX clash[1431]: time="2020-07-29T23:46:48+08:00" level=info msg="[TCP] 127.0.0.1:35960 --> dl.google.com match DomainSuffix using Proxy[op]"
7月 29 23:46:48 ubuntu-X550JX clash[1431]: time="2020-07-29T23:46:48+08:00" level=info msg="[TCP] 127.0.0.1:35962 --> www.charlesproxy.com match Match using auto[op]"
7月 29 23:46:48 ubuntu-X550JX clash[1431]: time="2020-07-29T23:46:48+08:00" level=info msg="[TCP] 127.0.0.1:35970 --> ppa.launchpad.net match Match using auto[op]"
7月 29 23:46:48 ubuntu-X550JX clash[1431]: time="2020-07-29T23:46:48+08:00" level=info msg="[TCP] 127.0.0.1:35966 --> archive.ubuntu.com match Match using auto[op]"
7月 29 23:46:48 ubuntu-X550JX clash[1431]: time="2020-07-29T23:46:48+08:00" level=info msg="[TCP] 127.0.0.1:35972 --> download.zerotier.com match Match using auto[op]"
7月 29 23:46:50 ubuntu-X550JX clash[1431]: time="2020-07-29T23:46:50+08:00" level=info msg="[TCP] 127.0.0.1:35982 --> ppa.launchpad.net match Match using auto[op]"

Reference

How to Set the Proxy for APT on Ubuntu 18.04

comments powered by Disqus