「APT」- 使用代理服务(提升速度)

  CREATED BY JENKINSBOT

问题描述

有时需要使用 SOCKS/HTTP(S) 代理进行软件包下载,以提高网络下载速度。

本笔记将记录如何为 APT 配置 SOCKS5/HTTP(S) 代理。

操作系统:Kali GNU/Linux Rolling / apt 1.8.4 (amd64)

解决方法

方法一、使用配置文件

创建 /etc/apt/apt.conf.d/99socks.conf 配置:

cat > /etc/apt/apt.conf.d/99socks.conf <<EOF
Acquire::http::proxy "socks5h://127.0.0.1:1080";
EOF

方法二、命令行指定(推荐)

http_proxy='http://127.0.0.1:8123' apt-get update

注意事项,应该使用 http_proxy,而不是 HTTP_PROXY 变量。

相关文档

man 5 apt.conf
man apt-transport-http
man apt-transport-https

附加说明

Differentiate socks5h from socks5 and socks4a from socks4 when handling proxy string #1035
In a proxy string,
socks5h:// and socks4a:// mean that the hostname is resolved by the SOCKS server.
socks5:// and socks4:// mean that the hostname is resolved locally.
socks4a:// means to use SOCKS4a, which is an extension of SOCKS4.

参考文献

syntax for SOCKS proxy in apt.conf
How to use “apt-get” via “Http-proxy” like this?