文档章节

Xfce设置代理Proxy

码农小骚年
 码农小骚年
发布于 2016/01/11 09:12
字数 1804
阅读 2759
收藏 1

在Debian系的Linux系统中,可以编辑/etc/environment文件,增加下面几行:

http_proxy=http://myproxy.server.com:8080/
https_proxy=http://myproxy.server.com:8080/
ftp_proxy=http://myproxy.server.com:8080/
no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
HTTP_PROXY=http://myproxy.server.com:8080/
HTTPS_PROXY=http://myproxy.server.com:8080/
FTP_PROXY=http://myproxy.server.com:8080/
NO_PROXY="localhost,127.0.0.1,localaddress,.localdomain.com"

然后执行

$ source /etc/environment

这时候,大部分的软件都可以通过代理上网了。

还有一部分使用Gnome配置的软件仍然不能上网,可以这样解决,命令行:

gsettings set org.gnome.system.proxy mode 'manual' 
gsettings set org.gnome.system.proxy.http host 'myproxy.server.com'
gsettings set org.gnome.system.proxy.http port 8080

对于apt来说,还可以这样设定:

在/etc/apt/apt.conf.d/下创建一个文件,比如可以是:95proxies,内容是:

Acquire::http::proxy "http://myproxy.server.com:8080/";
Acquire::ftp::proxy "ftp://myproxy.server.com:8080/";
Acquire::https::proxy "https://myproxy.server.com:8080/";

当然,还有大神写的开启和关闭proxy的Bash:

proxyon.sh:

if [ $(id -u) -ne 0 ]; then
  echo "This script must be run as root";
  exit 1;
fi

if [ $# -eq 2 ]
  then

  gsettings set org.gnome.system.proxy mode 'manual' ;
  gsettings set org.gnome.system.proxy.http host '$1';
  gsettings set org.gnome.system.proxy.http port $2;


  grep PATH /etc/environment > lol.t;
  printf \
  "http_proxy=http://$1:$2/\n\
  https_proxy=http://$1:$2/\n\
  ftp_proxy=http://$1:$2/\n\
  no_proxy=\"localhost,127.0.0.1,localaddress,.localdomain.com\"\n\
  HTTP_PROXY=http://$1:$2/\n\
  HTTPS_PROXY=http://$1:$2/\n\
  FTP_PROXY=http://$1:$2/\n\
  NO_PROXY=\"localhost,127.0.0.1,localaddress,.localdomain.com\"\n" >> lol.t;

  cat lol.t > /etc/environment;


  printf \
  "Acquire::http::proxy \"http://$1:$2/\";\n\
  Acquire::ftp::proxy \"ftp://$1:$2/\";\n\
  Acquire::https::proxy \"https://$1:$2/\";\n" > /etc/apt/apt.conf.d/95proxies;

  rm -rf lol.t;

  else

  printf "Usage $0 <proxy_ip> <proxy_port>\n";

fi

proxyoff.sh:

if [ $(id -u) -ne 0 ]; then
  echo "This script must be run as root";
  exit 1;
fi

gsettings set org.gnome.system.proxy mode 'none' ;

grep PATH /etc/environment > lol.t;
cat lol.t > /etc/environment;

printf "" > /etc/apt/apt.conf.d/95proxies;

rm -rf lol.t;

使用方法如下:

 $ sudo ./proxyon.sh 10.2.20.17 8080
 OR
 $ sudo ./proxyon.sh myproxy.server.com 8080
 $ sudo ./proxyoff.sh

更多的Bash也有这样写的(前面管用了,你可以忽略,我只是记录一下):

Some programs, such as wget and (used by pacman) curl, use environment variables of the form "protocol_proxy" to determine the proxy for a given protocol (e.g. HTTP, FTP, ...).

Below is an example on how to set these variables in a shell:

 export http_proxy=http://10.203.0.1:5187/
 export https_proxy=$http_proxy
 export ftp_proxy=$http_proxy
 export rsync_proxy=$http_proxy
 export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"

Some programs look for the all caps version of the environment variables.

If the proxy environment variables are to be made available to all users and all applications, the above mentioned export commands may be added to a script, say "proxy.sh" inside /etc/profile.d/. The script has to be then made executable. This method is helpful while using a Desktop Environment like Xfce which does not provide an option for proxy configuration. For example, Chromium browser will make use of the variables set using this method while running XFCE.

Alternatively you can automate the toggling of the variables by adding a function to your .bashrc (thanks to Alan Pope for original script idea)

function proxy_on() {
    export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"

    if (( $# > 0 )); then
        valid=$(echo $@ | sed -n 's/\([0-9]\{1,3\}.\)\{4\}:\([0-9]\+\)/&/p')
        if [[ $valid != $@ ]]; then
            >&2 echo "Invalid address"
            return 1
        fi

        export http_proxy="http://$1/"
        export https_proxy=$http_proxy
        export ftp_proxy=$http_proxy
        export rsync_proxy=$http_proxy
        echo "Proxy environment variable set."
        return 0
    fi

    echo -n "username: "; read username
    if [[ $username != "" ]]; then
        echo -n "password: "
        read -es password
        local pre="$username:$password@"
    fi

    echo -n "server: "; read server
    echo -n "port: "; read port
    export http_proxy="http://$pre$server:$port/"
    export https_proxy=$http_proxy
    export ftp_proxy=$http_proxy
    export rsync_proxy=$http_proxy
    export HTTP_PROXY=$http_proxy
    export HTTPS_PROXY=$http_proxy
    export FTP_PROXY=$http_proxy
    export RSYNC_PROXY=$http_proxy
}

function proxy_off(){
    unset http_proxy
    unset https_proxy
    unset ftp_proxy
    unset rsync_proxy
    echo -e "Proxy environment variable removed."
}

Omit username or password if they are not needed.

As an alternative, you may want to use the following script. Change the strings "YourUserName", "ProxyServerAddress:Port", "LocalAddress" and "LocalDomain" to match your own data, then edit your ~/.bashrc to include the edited functions. Any new bash window will have the new functions. In existing bash windows, type source ~/.bashrc. You may prefer to put function definitions in a separate file like functions then add source functions to .bashrc instead of putting everything in .bashrc. You may also want to change the name "myProxy" into something short and easy to write.

 #!/bin/bash

 assignProxy(){
   PROXY_ENV="http_proxy ftp_proxy https_proxy all_proxy HTTP_PROXY HTTPS_PROXY FTP_PROXY ALL_PROXY"
   for envar in $PROXY_ENV
   do
     export $envar=$1
   done
   for envar in "no_proxy NO_PROXY"
   do
      export $envar=$2
   done
 }

 clrProxy(){
   assignProxy "" # This is what 'unset' does.
 }

 myProxy(){
   user=YourUserName
   read -p "Password: " -s pass &&  echo -e " "
   proxy_value="http://$user:$pass@ProxyServerAddress:Port"
   no_proxy_value="localhost,127.0.0.1,LocalAddress,LocalDomain.com"
   assignProxy $proxy_value $no_proxy_value
 }

Keep proxy through sudo

If the proxy environment variables are set for the user only (say, from manual commands or .bashrc) they will get lost when running commands with sudo (or when programs use sudo intenally).

A way to prevent that is to add the following line to the sudo configuration file (accessible with visudo) :

Defaults env_keep += "http_proxy https_proxy ftp_proxy"

You may also add any other environment variable, like rsync_proxy, or no_proxy.

Automation with network managers

  • NetworkManager cannot change the environment variables.

  • netctl could set-up these environment variables but they would not be seen by other applications as they are not child of netctl.

About libproxy

libproxy (which is available in the extra repository) is an abstraction library which should be used by all applications that want to access a network resource. It still is in development but could lead to a unified and automated handling of proxies in GNU/Linux if widely adopted.

The role of libproxy is to read the proxy settings form different sources and make them available to applications which use the library. The interesting part with libproxy is that it offers an implementation of the Web Proxy Autodiscovery Protocol and an implementation of Proxy Auto-Config that goes with it.

The /usr/bin/proxy binary takes URL(s) as argument(s) and returns the proxy/proxies that could be used to fetch this/these network resource(s).

Note: the version 0.4.11 does not support http_proxy='wpad:' because { pkg-config 'mozjs185 >= 1.8.5'; } fails .

As of 06/04/2009 libproxy is required by libsoup. It is then indirectly used by the Midori browser.

Web Proxy Options

  • Squid is a very popular caching/optimizing proxy

  • Privoxy is an anonymizing and ad-blocking proxy

  • For a simple proxy, ssh with port forwarding can be used

Simple Proxy with SSH

Connect to a server (HOST) on which you have an account (USER) as follows

ssh -D PORT USER@HOST

For PORT, choose some number which is not an IANA registered port. This specifies that traffic on the local PORT will be forwarded to the remote HOST. ssh will act as a SOCKS server. Software supporting SOCKS proxy servers can simply be configured to connect to PORT on localhost.

Using a SOCKS proxy

There are two cases:

  • the application you want to use handles SOCKS5 proxies (for example Firefox), then you just have to configure it to use the proxy.

  • the application you want to use does not handle SOCKS proxies, then you can try to use tsocks or proxychains-ng.

In Firefox, you can use the SOCKS proxy in the menu Preferences > Network > Settings. Choose "Manual Proxy Configuration", and set the SOCKS Host (and only this one, make sure the other fields, such as HTTP Proxy or SSL Proxy are left empty). For example, if a SOCKS5 proxy is running on localhost port 8080, put "127.0.0.1" in the SOCKS Host field, "8080" in the Port field, and validate.

If using proxychains-ng, the configuration takes place in /etc/proxychains.conf. You may have to uncomment the last line (set by default to use Tor), and replace it with the parameters of the SOCKS proxy. For example, if you are using the same SOCKS5 proxy as above, you will have to replace the last line by:

socks5 127.0.0.1 8080

Then, proxychains-ng can be launched with

proxychains <program>

Where <program> can be any program already installed on your system (e.g. xterm, gnome-terminal, etc).

If using tsocks, the configuration takes place in /etc/tsocks.conf. See man 5 tsocks.conf for the options. An example minimum configuration looks like this:

/etc/tsocks.conf
server = 127.0.0.1
server_port = 8080
server_type = 5

Proxy settings on GNOME3

Some programs like Chromium prefer to use the settings stored by gnome. These settings can be modified through the gnome-control-center front end and also through gsettings.

gsettings set org.gnome.system.proxy mode 'manual' 
gsettings set org.gnome.system.proxy.http host 'proxy.localdomain.com'
gsettings set org.gnome.system.proxy.http port 8080
gsettings set org.gnome.system.proxy.ftp host 'proxy.localdomain.com'
gsettings set org.gnome.system.proxy.ftp port 8080
gsettings set org.gnome.system.proxy.https host 'proxy.localdomain.com'
gsettings set org.gnome.system.proxy.https port 8080
gsettings set org.gnome.system.proxy ignore-hosts "['localhost', '127.0.0.0/8', '10.0.0.0/8', '192.168.0.0/16', '172.16.0.0/12' , '*.localdomain.com' ]"

This configuration can also be set to automatically execute when Network Manager connects to specific networks , by using the package proxydriverAUR from the AUR

Microsoft NTLM proxy

In a Windows network, NT LAN Manager (NTLM) is a suite of Microsoft security protocols which provides authentication, integrity, and confidentiality to users.

cntlmAUR from the AUR stands between your applications and the NTLM proxy, adding NTLM authentication on-the-fly. You can specify several "parent" proxies and Cntlm will try one after another until one works. All authenticated connections are cached and reused to achieve high efficiency.

(NTLM PROXY IP:PORT + CREDENTIALS + OTHER INFO) -----> (127.0.0.1:PORT)

Configuration

Change settings in /etc/cntlm.conf as needed, except for the password. Then run:

$ cntlm -H

This will generate encrypted password hashes according to your proxy hostname, username and password.

Warning: ettercap can easily sniff your password over LAN when using plain-text passwords instead of encrypted hashes.

Edit /etc/cntlm.conf again and include all three generated hashes, then enable cntlm.service.

To test settings, run:

$ cntlm -v

Usage

Use 127.0.0.1:<port> or localhost:<port> as a proxy adress. <port> matches the Listen parameter in /etc/cntlm.conf, which by default is 3128.

参考文献:

http://askubuntu.com/questions/150210/how-do-i-set-systemwide-proxy-servers-in-xubuntu-lubuntu-or-ubuntu-studio

https://wiki.archlinux.org/index.php/proxy_settings

本文转载自:http://askubuntu.com/questions/150210/how-do-i-set-systemwide-proxy-servers-in-xubuntu-lubuntu-or...

码农小骚年
粉丝 1
博文 15
码字总数 4179
作品 0
大庆
私信 提问
Debian8.5精简安装说明

说明:这个安装不是很适合Linux新手的,要有一定的基础才能用起来舒心。一切以简洁/稳定为主,不考虑任何的美化……想美化安装完之后再自己Google吧(或者百度)。还有,我没有独门显卡,据说...

码农小骚年
2016/07/14
397
0
windows环境下设置命令行CMD、Git、NPM、Bower和Gem代理设置

在公司的电脑只能通过设置代理访问外网时,需要设置代理 命令行CMD代理设置 代理不需要密码时,在命令行界面输入: 代理需要用户密码时,在命令行界面输入: 或者 Git代理设置 类似,git设置...

dhb_oschina
2016/04/21
2.3K
0
Linux代理环境连接外网时,给yum, apt-get和linux网络配置代理

一、给CentOS的yum和wget配置代理 在公司中为了网络安全,通常需要用代理才能连接外网。这种情况下安装的Linux机器无法也无法直接连上yum服务器,导致安装软件很不方便。 解决方法就是,也给...

dhb_oschina
2015/12/01
1K
0
Apache配置正向代理与反向代理

Apache配置正向代理与反向代理 1. 正向代理 配置正向代理很简单,此处我们配置vhost来实现代理, 只需要在浏览器的Proxy选项里加入你的Apache配置的vHost主机即可 1.1 开启Apache代理模块并引...

逝者的梦
2015/08/11
49
0
给Android Studio设置代理

在进行代理设置前,首先你得有代理服务器。如果没有,可参见我前一篇文章《使用傻瓜包goagent翻墙》。 下面,我假定我的代理服务器的IP为192.168.137.1(局域网里面用)或127.0.0.1(本机中使...

天王盖地虎626
01/12
2.3K
0

没有更多内容

加载失败,请刷新页面

加载更多

刚哥谈架构 (二) 我眼中的架构师

之前在公司,有小伙伴在向别人介绍我的时候,经常会有人这么说:“刚哥是我们的architcture”,如果来人是老外,心中一定是一惊,心中暗叹,“这位匪首看上去貌不惊人,难道已经做到了架构和...

naughty
41分钟前
3
0
OSChina 周日乱弹 —— 别问,问就是没空

Osc乱弹歌单(2019)请戳(这里) 【今日歌曲】 @tom_tdhzz :#今日歌曲推荐# 分享容祖儿/彭羚的单曲《心淡》: 《心淡》- 容祖儿/彭羚 手机党少年们想听歌,请使劲儿戳(这里) @wqp0010 :周...

小小编辑
今天
111
4
golang微服务框架go-micro 入门笔记2.1 micro工具之micro api

micro api micro 功能非常强大,本文将详细阐述micro api 命令行的功能 重要的事情说3次 本文全部代码https://idea.techidea8.com/open/idea.shtml?id=6 本文全部代码https://idea.techidea8....

非正式解决方案
今天
5
0
Spring Context 你真的懂了吗

今天介绍一下大家常见的一个单词 context 应该怎么去理解,正确的理解它有助于我们学习 spring 以及计算机系统中的其他知识。 1. context 是什么 我们经常在编程中见到 context 这个单词,当...

Java知其所以然
昨天
5
0
Spring Boot + Mybatis-Plus 集成与使用(二)

前言: 本章节介绍MyBatis-Puls的CRUD使用。在开始之前,先简单讲解下上章节关于Spring Boot是如何自动配置MyBatis-Plus。 一、自动配置 当Spring Boot应用从主方法main()启动后,首先加载S...

伴学编程
昨天
8
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部