Linux 命令行关闭代理

Sea*_*yen 28 bash proxy ubuntu

当我在 Ubuntu 中使用命令行终端时,你能告诉我关闭代理的命令行吗?

nel*_*aro 30

正如另一个答案所说,有些程序根本不查看系统,您可能需要单独设置它们。例如 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/"  
Run Code Online (Sandbox Code Playgroud)

没有统一设置其他使用env

$ 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/  
Run Code Online (Sandbox Code Playgroud)

我会检查 ~/.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
Run Code Online (Sandbox Code Playgroud)


小智 20

假设您在谈论典型的命令行软件和 HTTP 代理:

大多数命令行工具从环境变量中获取它HTTP_PROXY,因此在运行命令之前:

unset HTTP_PROXY

软件/平台之间可能存在一些差异,您可能也需unset http_proxy要这样做。

请注意,许多程序将此信息存储在它们自己的配置文件中,并且可能会忽略环境,因此您必须逐个解决这些问题。


Adr*_*o P 12

您可以在 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
Run Code Online (Sandbox Code Playgroud)

您还可以为您添加快捷方式~/.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
}
Run Code Online (Sandbox Code Playgroud)

不要忘记重新加载 .bashrc:

$ . ~/.bashrc
Run Code Online (Sandbox Code Playgroud)

或者

$ source ~/.bashrc
Run Code Online (Sandbox Code Playgroud)

[S]hell Hacks 中的更多详细信息。


aru*_*uuu 9

要在当前会话的一行中禁用所有代理变量:

unset `env | grep proxy | cut -d= -f1`
Run Code Online (Sandbox Code Playgroud)


小智 5

export http_proxy=
Run Code Online (Sandbox Code Playgroud)

您可以通过运行来检查它们是否消失

echo $http_proxy
Run Code Online (Sandbox Code Playgroud)

它应该返回一个空行