Ubuntu 设置代理


目录

  1. Ubuntu环境

  2. 设置代理

设置Ubuntu环境

edit: 2022/5/24

Ubuntu version: 20.10

设置代理

/etc/envirement

在登录时操作系统使用的第二个文件,系统在读取你自己的profile前,设置环境文件的环境变量。

特点:作用域时全局;永久性;apt、wget、curl可以使用。

http_proxy=http://127.0.0.1:911
https_proxy=http://127.0.0.1:912
no_proxy=abc.com,.abc.com,localhost,127.0.0.0/8

HTTP_PROXY=http://127.0.0.1:911
HTTPS_PROXY=http://p//127.0.0.1:912
NO_PROXY=abc.com,.abc.com,localhost,127.0.0.0/8

/etc/profile.d/

该文件为系统的每个用户设置环境信息,当用户第一个登录时,该文件会被执行。并从/etc/profile.d目录的配置文件中收集shell的配置。

特点:作用域时全局;永久性;apt、wget、curl可以使用。

在/etc/profile.d/下添加一个脚本文件:proxy.sh

sudo vim /etc/profile.d/proxy.sh
sudo chmod +x /etc/profile.d/proxy.sh

文件内容

export http_proxy="http://127.0.0.1:8080/"
export https_proxy="http://127.0.0.1:8080/"
export no_proxy="127.0.0.1,localhost/"

export HTTP_PROXY="http://127.0.0.1:8080/"
export HTTPS_PROXY="http://127.0.0.1:8080/"
export NO_PROXY="127.0.0.1,localhost/"

使文件生效

source /etc/profile.d/proxy.sh
# check env
env | grep -i proxy
 

/ect/profile

/etc/bash.bashrc

为每一个运行bash shell的用户执行此文件,当bash shell 被打开时,该文件被读取。

特点:作用于所有用户

在/etc/bash.bashrc中添加代理

export http_proxy=http://yourproxy:port
export https_proxy=http://yourproxy:port

~/.profile

每个用户都可使用该文件输入专用于自己的shell信息,当用户登录时,该文件被执行一次。默认情况下,它设置一些环境变量,执行用户的.bashrc 文件。

特点:作用于当前用户;

~/.bashrc

该文件包含专用于的bash shell信息,当登录时以及每次打开新的shell时,该文件被读取。

特点:作用于当前用户;

在~/.bashrc中添加代理

export http_proxy=http://yourproxy:port
export https_proxy=http://yourproxy:port

使文件生效

source ~/.bashrc

测试结果:

  • sudo apt-get update 不可以使用
  • 作用于当前用户
  • wget 可以使用
  • curl 可以使用

apt-get

在/etc/apt/apt.conf.d/下添加30proxy或者80proxy,也可以在/etc/apt/下添加apt.conf文件

sudo vim /etc/apt/apt.conf

文件中内容

Acquire::http::proxy "http://127.0.0.1:8080";
Acquire::https::proxy "http://127.0.0.1:8080";

浏览器上网

打开Settings > Network > Network Proxy > Manual,添加代理

git

设置全局代理

git config --global http.proxy http://127.0.0.1:8080

git config --global https.proxy http://127.0.0.1:8080

删除全局代理

git config --global --unset http.proxy

git config --global --unset https.proxy

设置github代理

git config --global http.https://github.com.proxy socks5://127.0.0.1:1080

删除github代理

git config --global --unset http.https://github.com.proxy

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM