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