Linux命令列關閉代理

Linux命令列關閉代理

當我在 Ubuntu 中使用命令列終端機時,你能告訴我關閉代理程式的命令列嗎?

答案1

正如另一個答案所說,有些程式根本不考慮系統,您可能需要單獨設定它們。例如,wget 有許多代理選項,可用於在執行期間忽略或調整環境代理配置。以下是可以設定係統代理的多個區域。

  • 我的系統看起來如何,請注意,您必須更改網路環境的指定係統配置。

一些Linux系統使用/etc/environment

$ cat /etc/environment 
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
http_proxy="http://192.168.1.250:8080/"
ftp_proxy="ftp://192.168.1.250:8080/"
https_proxy="https://192.168.1.250:8080/"  

沒有統一的單一設置其他使用環境

$ env | grep -i proxy
NO_PROXY=localhost,127.0.0.0/8,127.0.1.1
http_proxy=http://192.168.1.250:8080/
FTP_PROXY=ftp://192.168.1.250:8080/
ftp_proxy=ftp://192.168.1.250:8080/
all_proxy=socks://192.168.1.250:8080/
ALL_PROXY=socks://192.168.1.250:8080/
HTTPS_PROXY=https://192.168.1.250:8080/
https_proxy=https://192.168.1.250:8080/
no_proxy=localhost,127.0.0.0/8,127.0.1.1
HTTP_PROXY=http://192.168.1.250:8080/  

我會檢查 ~/.bashrc 以在系統啟動時自動套用設定。

$ man env
$ man set
$ # The file section near the end of the bash manual.
$ man bash 

FILES
       /bin/bash
              The bash executable
       /etc/profile
              The systemwide initialization file, executed for login shells
       /etc/bash.bashrc
              The systemwide per-interactive-shell startup file
       /etc/bash.bash.logout
              The systemwide login shell cleanup file, executed when  a  login
              shell exits
       ~/.bash_profile
              The personal initialization file, executed for login shells
       ~/.bashrc
              The individual per-interactive-shell startup file
       ~/.bash_logout
              The  individual  login shell cleanup file, executed when a login
              shell exits
       ~/.inputrc
              Individual readline initialization file

答案2

假設您正在談論典型的命令列軟體和 HTTP 代理:

大多數命令列工具都會從環境變數中取得此值HTTP_PROXY,因此在執行命令之前:

unset HTTP_PROXY

軟體/平台之間可能存在一些差異,您可能unset http_proxy也需要這樣做。

請注意,許多程式將此資訊儲存在自己的設定檔中,並且可能會忽略環境,因此您必須根據具體情況來解決這些問題。

答案3

您可以在 bash 中一次設定或取消設定所有變數:

$ export {http,https,ftp}_proxy="http://proxy-server:port"
$ unset {http,https,ftp}_proxy

$ export {HTTP,HTTPS,FTP}_PROXY="http://proxy-server:port"
$ unset {HTTP,HTTPS,FTP}_PROXY

您也可以新增快捷方式~/.bashrc

# Set Proxy
function setproxy() {
    export {http,https,ftp}_proxy="http://proxy-server:port"
    export {HTTP,HTTPS,FTP}_PROXY="http://proxy-server:port"
}

# Unset Proxy
function unsetproxy() {
    unset {http,https,ftp}_proxy
    unset {HTTP,HTTPS,FTP}_PROXY
}

不要忘記重新載入 .bashrc:

$ . ~/.bashrc

或者

$ source ~/.bashrc

更多詳情請參見[S]地獄駭客

答案4

export http_proxy=

您可以透過運行來檢查它們是否消失

echo $http_proxy

它應該傳回一個空行

相關內容