笔记:Linux系统代理设置

本文最后更新于:2021-05-09

Linux下设置代理问题

Ref:

Proxy server - ArchWiki
Environment variables - ArchWiki
这两篇文档基本可以解决Linux下设置代理的各种问题

How To Use Proxy Server To Access Internet at Shell Prompt With http_proxy Variable
这篇是简单操作版


之前找了好多教程,都没搞清楚
到头来,发现还是好文档最靠谱


2019/12/23 更新

  • 环境变量设置代理
    ~/.bashrc添加
    1
    2
    3
    4
    5
    export http_proxy=http://<proxy_addr>:<proxy_port>/
    export https_proxy=$http_proxy
    export ftp_proxy=$http_proxy
    export rsync_proxy=$http_proxy
    export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"

2021/05/09 update

1
2
3
# vim /etc/sudoers.d/05_proxy

Defaults env_keep += "*_proxy *_PROXY"

Ref: ArchWiki - Proxy server: Keep proxy through sudo

  • Snap下载使用代理
    参考 How to install snap packages behind web proxy on Ubuntu 16.04
    命令行敲

    1
    2
    $ sudo snap set system proxy.http="http://<proxy_addr>:<proxy_port>"
    $ sudo snap set system proxy.https="http://<proxy_addr>:<proxy_port>"
  • ubuntu sudo继承代理
    参考 How to keep environment variables when using sudo
    ubuntu的似乎还有一点区别,不能写在一行里面

    1
    2
    3
    4
    5
    6
    7
    8
    sudo visudo

    # For Ubuntu 14, you need to specify in separate lines as it returns the errors for multi-variable lines:
    Defaults env_keep += "http_proxy"
    Defaults env_keep += "https_proxy"
    Defaults env_keep += "HTTP_PROXY"
    Defaults env_keep += "HTTPS_PROXY"


2021/04/10 update

curl and pacman

Ref: ArchWiki - Proxy server: crul and pacman

You may set the all_proxy environment variable to let curl and pacman (which uses curl) use your socks5 proxy:
$ export all_proxy="socks5://your.proxy:1080"


本博客所有文章除特别声明外,均采用 CC BY-NC-ND 4.0协议 。转载请注明出处~