python - Linux终端全局代理翻墙
PHP中文网
PHP中文网 2017-04-18 09:34:01
0
2
2097

我想通过设置HTTP_PROXY和HTTPS_PROXY方法实现代理,格式如下

$ export HTTP_PROXY="http[socks5]://user:pass@server_address:port/"
$ export HTTPS_PROXY="http[socks5]://user:pass@server_address:port/"

昨天我买了一台阿里云的服务器,经过SSH -D user@server然后通过Chrome下的proxy插件可以实现翻墙。现在我想让用设置环境变量的方式代理实现终端下也能访问Goole等网站的页面,请问我应该怎样在我的阿里云服务器上面配置呢?

附录:
自己在Python爬虫里面通过下面的方式利用Shadowsocks已经可以爬取墙外的网站了,现在主要想在终端下使用wget, youtube-dl等命令翻墙。

 proxy_handler = SocksiPyHandler(socks.SOCKS5, '127.0.0.1', 1080)
PHP中文网
PHP中文网

认证0级讲师

reply all(2)
小葫芦

For your title, if you want to achieve the purpose of global proxy , you can read the iptables part of this article

https://linuxaria.com/article...

I excerpted itiptablesThe configuration is as follows:

#!/bin/bash
# Create new chain
iptables -t nat -N REDSOCKS
 
# Ignore LANs and some other reserved addresses.
iptables -t nat -A REDSOCKS -d 0.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 10.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 127.0.0.0/8 -j RETURN
iptables -t nat -A REDSOCKS -d 169.254.0.0/16 -j RETURN
iptables -t nat -A REDSOCKS -d 172.16.0.0/12 -j RETURN
iptables -t nat -A REDSOCKS -d 192.168.0.0/16 -j RETURN
iptables -t nat -A REDSOCKS -d 224.0.0.0/4 -j RETURN
iptables -t nat -A REDSOCKS -d 240.0.0.0/4 -j RETURN
 
# Anything else should be redirected to port 31338
iptables -t nat -A REDSOCKS -p tcp -j REDIRECT --to-ports 31338
 
# Any tcp connection made by `linuxaria' should be redirected, put your username here.
iptables -t nat -A OUTPUT -p tcp -m owner --uid-owner linuxaria -j REDSOCKS

This configuration forwards all TCP connections except local LAN connections to port 31338. Obviously you should use proxy software to monitor this port in advance. Of course, it can also be any other designated proxy listening port.

PS: Global proxy is actually very impractical. It’s better to separate application proxies. As for what you said, just use wget这些命令也使用代理的话, 用之前临时exportenv and that’ll be fine

For example, my proxy is thrown under 192.168.100.100上面, 端口1080, 我要wget YouTube:

$ export https_proxy=http://192.168.100.100:1080
$ wget www.youtube.com
--2016-09-06 13:00:28--  http://www.youtube.com/
Connecting to 192.168.100.100:1080... connected.
Proxy request sent, awaiting response... 301 Moved Permanently
Location: https://www.youtube.com/ [following]
--2016-09-06 13:00:32--  https://www.youtube.com/
Connecting to 192.168.100.100:1080... connected.
Proxy request sent, awaiting response... 200 OK
Length: unspecified [text/html]
Saving to: “index.html”

    [           <=>                                 ] 391,815      133K/s   in 2.9s    

2016-09-06 13:00:36 (133 KB/s) - “index.html” saved [391815]

Easy and enjoyable, of course some applications may not support itSocks5协议, 直接搜"socks5 to http"一堆答案, 我一般用privoxy

PHPzhong

Regarding proxy, we recommend two tools, proxychains and privoxy. Like wget and youtube-dl, you can specify the proxy in the parameters, so if you have an ss server, just set up the ss proxy locally. I think it's better to use proxies for applications rather than creating system-level global proxies.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template