Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

Ubuntu 設定網路代理:終端、系統與瀏覽器三種層級

在公司裡用 Ubuntu,上網往往得先過代理這一關,而且瀏覽器要能出外網、終端也要能下載套件,兩邊都得處理。

一、終端代理(apt-get)

編輯 apt 的設定檔,把下面兩行加進去即可。注意 username 是代理帳號、password 是密碼(有特殊字元要轉義),proxyserver 與 port 換成自己的:

vim /etc/apt/apt.conf

Acquire::http::proxy "https://username:password@proxyserver:port/";
Acquire::https::proxy "https://username:password@proxyserver:port/";

實際範例:

Acquire::http::proxy "https://rongyux:abc123@dl-proxy.neusoft.com:8080/";
Acquire::https::proxy "https://rongyux:abc123@dl-proxy.neusoft.com:8080/";

其他走 apt 的指令,原理都一樣。

二、系統代理

編輯 /etc/profile,加入三行環境變數:

vim /etc/profile

export http_proxy=https://username:password@proxyserver:port
export https_proxy=https://username:password@proxyserver:port
export ftp_proxy=https://username:password@proxyserver:port

實際範例:

export http_proxy=https://rongyux:abc123@dl-proxy.neusoft.com:8080
export https_proxy=https://rongyux:abc123@dl-proxy.neusoft.com:8080
export ftp_proxy=https://rongyux:abc123@dl-proxy.neusoft.com:8080

讓設定生效:

source /etc/profile

這一步做完,瀏覽器只要選「使用系統代理」就能上網。

三、瀏覽器代理

以 Firefox 為例:設定 → 進階 → 網路 → 設定,改成手動設定代理,填入代理主機與埠號。

Ubuntu 設定網路代理:終端、系統與瀏覽器三種層級

三層都設好之後,不論是抓網頁還是在終端下載套件,都能順利穿透公司防火牆。若代理需要走 https,記得把 https_proxy 也一起設定,否則會出現只有部分流量繞得過去的情況。

Copyright © Linux教程網 All Rights Reserved