redsocks 设置全局代理

ref:  

How to install and configure Redsocks on Centos Linux

echo "The release dist is "$RELEASE
if [ x$RELEASE == "xUbuntu" ]; then
    SERVICE=`dpkg -l redsocks | grep redsocks`
    if [ $? != 0 ]; then
        echo $SERVICE
        sudo apt-get install redsocks
    fi
    SERVICE=`dpkg -l autossh | grep autossh`
    if [ $? != 0 ]; then
        echo $SERVICE
        sudo apt-get install autossh
    fi
else
    sudo curl http://$LINUX_FTP/pub/mirrors/fedora/epel/RPM-GPG-KEY-EPEL-7 -o /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
    # https://crosp.net/blog/administration/install-configure-redsocks-proxy-centos-linux/
    sudo yum install libevent libevent-devel
    cd redsocks/
    make
    sudo ./redsocks -c /etc/redsocks.conf
    git clone https://github.com/darkk/redsocks --config "http.proxy=http://proxy-shz.glb.intel.com:911/"
    # sudo yum install -y redsocks-0.4+dfsg-3.x86_64.rpm
    # sudo adduser --system --home /var/run/redsocks --no-create-home -U redsocks
    # sudo yum install -y autossh
fi

 


下载这个脚本

https://github.com/shaohef/redsocks_proxy

用这个覆盖配置

http://www.cnblogs.com/shaohef/p/8033295.html

 

分享一下我的经验,

 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 REDSOCKS -d 104.130.159.134/32 -p tcp -m tcp --dport 29418 -j DNAT --to-destination 127.0.0.1:6666
# iptables -t nat -A REDSOCKS -p tcp -j DNAT --to-destination 127.0.0.1:6666
# iptables -t nat -A REDSOCKS -p udp -j DNAT --to-destination 127.0.0.1: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

posted @ 2015-05-04 22:28  lvmxh  阅读(6978)  评论(1编辑  收藏  举报