redsocks 设置全局代理

分享一下我的经验,

 http://lilydjwg.is-programmer.com/2014/2/7/linux-really-global-http-proxy.42701.html

 

1. 优点: 设置一次,全局代理。连虚拟机都不要设置代理。

2. 缺点: 会停止工作,我把它放到crontab里。

 

1. 编译redsocks https://github.com/darkk/redsocks.

 

2. proxy.sh

 

iptables -t nat -N REDSOCKS || true

iptables -t nat -F REDSOCKS

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

iptables -t nat -A REDSOCKS -p tcp -j REDIRECT --to-ports 6666

iptables -t nat -A REDSOCKS -p udp -j REDIRECT --to-ports 8888

iptables -t nat -A OUTPUT -p tcp -j REDSOCKS

pkill redsocks

/root/bin/redsocks -c /root/bin/redsocks.conf

 

3. redsocks.conf

 

base {

log_debug = on;

log_info = on;

daemon = on;

redirector = iptables;

}

 

redsocks {

local_ip = 127.0.0.1;

local_port = 6666;

ip = 10.102.248.16; <---- proxy server IP.

port = 1080;

type = socks5;

}

redudp {

local_ip = 127.0.0.1;

local_port = 8888;

ip = 10.102.248.16;

port = 1080;

}

dnstc {

local_ip = 127.0.0.1;

local_port = 5300;

 

Ubuntu 下服务开机自启动。

http://askubuntu.com/questions/19320/how-to-enable-or-disable-services

http://askubuntu.com/questions/9382/how-can-i-configure-a-service-to-run-at-startup

Ubuntu 下iptables 开机自启动

http://wiki.ubuntu.org.cn/IptablesHowTo

http://www.cnblogs.com/tonybuaa/archive/2013/06/01/3112666.html

你可能感兴趣的:(SOC)