Total Pageviews

Friday, 8 April 2016

如何在Linux桌面系统/mac上,替终端设置http代理



vi /etc/profile
在最下面加入
export http_proxy=http://ip:port
保存、退出
source /etc/profile
----------------

三种方式:
1.在gnome 环境下可以使用命令:
gnome-network-properties

2.在命令行中添加:
export http_proxy="http://username:password@host:port"

3.修改文件/etc/profile,添加一行
export http_proxy="http://username:password@host:port"
然后
source /etc/profile

参考自:http://ubuntuforums.org/showthread.php?t=1575
------------------------------------------------------

如何为MacOS X的终端设置http代理

本文介绍如何在MacOS X终端里使用代理访问网络,虽然只在Mountain Lion下测试,但同样适用于装有Bash的系统。
实在无法忍受linode日本机房的高延迟,动手配置了一个goagent服务。但是HTTP代理和VPN不同,没法全局代理(至少不能简单配置),在Terminal里下载最新版本的Ruby,奇慢无比,下面介绍如何让Terminal里执行的程序使用goagent代理。

Socks代理
使用tsocks可以为任意程序提供socks代理
安装tsocks brewtapadamv/altbrewtapadamv/alt brew install tsocks ####配置tsocks 打开配置文件/usr/local/etc/tsocks.conf

修改如下:
local = 192.168.0.0/255.255.255.0
server = 127.0.0.1
server_type = 5
server_port = 8080

HTTP代理
$ export http_proxy='http://YOUR_USERNAME:YOUR_PASSWORD@PROXY_IP:PROXY_PORT/'
HTTPS代理
$ export https_proxy='http://YOUR_USERNAME:YOUR_PASSWORD@PROXY_IP:PROXY_PORT/'

取消HTTP/HTTPS代理
$ unset http_proxy
$ unset https_proxy

例子
让Terminal里的http访问走goagent的默认端口8087

$ export http_proxy='http://localhost:8087'
$ export https_proxy='http://localhost:8087'
$ tsocks /Applications/Textual.app/Contents/MacOS/Textual

使用Privoxy将socks代理转换为HTTP代理:
使用ssh -D可以获得一个socks5代理,privoxy可以将socks转换为http代理

安装privoxy:
brew install privoxy

修改配置文件vim /usr/local/etc/privoxy/config

listen-address  0.0.0.0:8118
forward-socks5 / localhost:1080 .

参考文章:
http://www.webupd8.org/2010/10/how-to-set-proxy-for-terminal-quick.html
https://whatbox.ca/wiki/tsocks
http://superuser.com/questions/280129/http-proxy-over-ssh-not-socks

from http://codelife.me/blog/2012/09/02/how-to-set-proxy-for-terminal/
-----------------------------------

Tunneling other applications

Several applications are natively socks aware. For example curl and any application using libcurl, for example via pycurl, is socks proxying aware. Set $ALL_PROXY to the SSH tunnel you created:
export ALL_PROXY=socks5://localhost:8800
You can use a network wrapper tsocks or similar to make other applications tunnel via socks proxy. There is atsocks.conf file here which corresponds roughly to the proxy.pac. Set $TSOCKS_CONF_FILE to the full path to the file, and prefix command line with tsocks to wrap the application:
export TSOCKS_CONF_FILE=/path/to/tsocks.conf
tsocks wget -SO- http://vocms144.cern.ch:1234/foo
---------------------------------------
surge for mac 是 http 代理,开着surge,终端里面要用到代理的时候就 运行:
export http_proxy=http://127.0.0.1:6152 

取消代理,就运行:
unset http_proxy

---------------------------

How to change Gnome Proxy Settings on a Terminal window


This document will show how to change proxy settings for Gnome from a terminal window (not from gnome-network-preferences).

The configuration information is saved under .gconf (front end GconfEdior), which is a system for storing application preference in Gnome (think Registry for Windows PC).

Keys can be accessed in terminal under “/home/user/.gconf/*”. The command below will display current proxy configuration loaded by gconf:

$ cat .gconf/system/http_proxy/%gconf.xml
This will be the same as:


The proxy configuration can be divided into two parts:
. /system/proxy/ – Configures SOCKS Proxy
. /system/http_proxy/ – Configures HTTP proxy

We can use gconftool -R to view the options within the subkeys. For the screenshot above we would get something similar to this:

$ gconftool -R /system/proxy
old_ftp_port = 0
socks_host = 127.0.0.1
mode = manual
old_socks_port = 0
secure_host = 127.0.0.1
ftp_host = 127.0.0.1
socks_port = 80
old_secure_host =
secure_port = 80
ftp_port = 80
old_ftp_host =
autoconfig_url =
old_secure_port = 0
old_socks_host =
$ gconftool -R /system/http_proxy
use_http_proxy = true
use_authentication = false
host = 127.0.0.1
authentication_user =
ignore_hosts = [localhost,127.0.0.0/8,*.local]
use_same_proxy = true
authentication_password =
port = 80

So, to edit the proxy to the same settings as the one shown on the screenshot, we would do the following:

$ gconftool -s /system/http_proxy/use_http_proxy -t bool true
$ gconftool -s /system/http_proxy/host -t int 127.0.0.1
$ gconftool -s /system/http_proxy/port -t int 80
$ gconftool -s /system/http_proxy/use_same_proxy -t bool true
$ gconf -s /system/proxy/mode -t string manual
------------
相关帖子:
http://briteming.blogspot.com/2016/03/linuxhttp.html