Linux命令行关闭代理


22

当我在Ubuntu中使用命令行终端时,能否向我显示关闭代理的命令行?


您需要在哪里禁用它?据我所知,代理服务器设置取决于应用程序。
Diskilla 2010年

Answers:


27

就像另一个答案所说的那样,有些程序根本看不到系统,您可能必须单独设置它们。例如,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

16

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

大多数命令行工具都是从环境变量中获取这些信息的HTTP_PROXY,因此在运行命令之前:

unset HTTP_PROXY

软件/平台之间可能会有一些差异,您可能也需要unset http_proxy

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


似乎需要重启...?
严景贤

5

您可以在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] hell Hacks中有更多详细信息。


这是一个很好的答案,但是当需要更改代理设置时,恐怕系统中还有更多地方:askubuntu.com/questions/664777/…
matandked

每个软件都可以使用自己的代理设置(例如npm或apt,仅举几例)。因此http_proxy涵盖了大多数内容,但是您需要查看文档以确保使用了哪个文档。
Adriano P

3

如果您希望更改GUI程序的代理,则如果它们使用Gnome的“系统”代理设置,则可能会有些成功。这些是可从“控制面板”设置的代理设置。

您可以使用gconftool查看然后更改当前设置:

$ gconftool-2 -a /system/http_proxy
  ignore_hosts = [localhost,127.0.0.0/8,*.local]
  authentication_user =
  authentication_password =
  use_authentication = false
  use_http_proxy = true
  port = 8080
  host = http://myproxy.mydomain.org/

要关闭代理-将use_http_proxy设置为false:

$ gconftool-2 -t bool -s /system/http_proxy/use_http_proxy false

您可以使用-a上面的线来检查结果。或者设置一个新的代理:

$ gconftool-2 -t string -s /system/http_proxy/host "http://newproxy.mydomain.org/"
$ gconftool-2 -t int -s /system/http_proxy/port 8088

3
export http_proxy=

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

echo $http_proxy

它应该返回一个空行


1

如果以上所有内容都不起作用:

  1. 进入系统设置。
  2. 转到网络。
  3. 转到网络代理,即使所选选项为“ none”,也转到“ manual”并删除所有已保存的代理。
  4. 在系统范围内应用。

这对我有用!


1
OP专门要求提供命令行选项。他们可能未安装GUI
Burgi

1

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

unset `env | grep proxy | cut -d= -f1`

0

您可以从/ etc / environment中删除所有{http_proxy,https_proxy}等。只需sudo gedit / etc / environment,然后手动删除所有这些代理并保存。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.