Ubuntu 18.04 LTS 設置代理(系統代理;http 代理;sock5 代理;apt 代理 ...)


1. 設置系統代理

1.1 設置 http 代理

1.1.1 只在當前 shell 生效

export http_proxy="http://<user>:<password>@<proxy_server>:<port>"
export https_proxy="http://<user>:<password>@<proxy_server>:<port>"
export ftp_proxy="http://<user>:<password>@<proxy_server>:<port>"


export all_proxy="http://<user>:<password>@<proxy_server>:<port>"

注意:
  • 其中  <user>:<password>  不一定需要,如果沒有可以不設置,則變為 export http_proxy="http://<proxy_server>:<port>"
  • 有些軟件識別不了小寫版本,可以在再設置一份大寫版本 HTTP_PROXY HTTPS_PROXY FTP_PROXY ALL_PROXY

1.1.2 全局生效

vim /etc/profile    #編輯全局配置文件
#TODO -> 在文件末尾添加 1.1.1 中的代理代碼,保存后關閉文件
source /etc/profile    #試配置文件生效

配置文件實例:

Image(9)[6]

1.2 為 WSL Ubuntu 18.04 LTS 配置 Windows 系統正在使用的 sock5 代理


1、安裝 python pip  (如果安裝失敗,關閉終端然后重新打開一個終端,重新安裝)

apt install python-pip

2、升級 pip  (如果安裝失敗,關閉終端然后重新打開一個終端,重新安裝)

pip install --upgrade pip

3、安裝 genpac 工具(如果安裝失敗,關閉終端然后重新打開一個終端,重新安裝)

pip install genpac

4、生成配置

#TODO -> 切換到想存配置文件的路徑
genpac --proxy="SOCKS5 127.0.0.1:1080" -o autoproxy.pac --gfwlist-url="https://raw .githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt"

5、編輯 /etc/profile  在文件最后添加,具體端口配置和 ss 客戶端保持一致。這里可以參考 1.1 的兩種設置方法。

export http_proxy=http://127.0.0.1:1080
export https_proxy=http://127.0.0.1:1080
export ftp_proxy=http://127.0.0.1:1080

6、source /etc/profile  讓配置生效

7、使用 curl www .google.com  查看代理是否開啟成功。

2. 分別給軟件設置代理

經過 1,大部分軟件都可以走代理了,但是還是有個別軟件走不了代理,需要針對性設置

2.1 為 apt 設置 http 代理

2.1.1 方法1

1、Create a new configuration file named proxy.conf

sudo touch /etc/apt/apt.conf.d/proxy.conf

2、Open the proxy.conf  file in a text editor

sudo vim /etc/apt/apt.conf.d/proxy.conf

3、Add the following line to set your HTTP proxy

Acquire::http::Proxy "http://<user>:<password>@<proxy_server>:<port>";

4、Add the following line to set your HTTPS proxy

Acquire::https::Proxy "http://<user>:<password>@<proxy_server>:<port>";

5、Save your changes and exit the text editor

6、Your proxy settings will be applied the next time you run Apt.

7、效果圖

Image(9)[7]

2.1.2 方法2

create a new file named proxy.conf  under the /etc/apt/apt.conf.d  directory, and then add the following lines:

Acquire {
HTTP::proxy "http://<user>:<password>@<proxy_server>:<port>";
HTTPS::proxy "http://<user>:<password>@<proxy_server>:<port>";
}




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM