Redsocks

在windows上,我们可以安装proxifier来做sock5代理,在centos上,我们可以安装Redsocks来做代理。

1、安装依赖

$ yum -y install libevent-devel git gcc

2、下载源码与编译

$ git clone https://github.com/darkk/redsocks
$ cd redsocks
$ make

此时,会在redsocks目录里生成可执行文件redsocks

3、拷贝到/usr/bin目录下

$ cp redsocks/redsocks /usr/bin/

4、创建配置文件

创建目录/etc/redsocks,创建文件/var/log/redsocks/redsocks.log

$ mkdir -p /etc/redsocks /var/log/redsocks
$ touch /var/log/redsocks/redsocks.log

然后创建配置文件/etc/redsocks/redsocks.conf,内容如下,

base {
        log_debug = off;
        log_info = on;
        log = "file:/var/log/redsocks/redsocks.log";
        daemon = off;
        redirector = iptables;
}
redsocks {
        local_ip = 127.0.0.1;
        local_port = 8881;
        ip = x.x.x.x;
        port = xx;
        type = socks5;
}

其中local_port表示redsocks在本机监听的端口,ip表示远程代理服务器的IP,port表示远程代理服务器的端口。

5、启动

执行以下命令启动

$ /usr/bin/redsocks -c /etc/redsocks/redsocks.conf &

6、添加代理规则

假设我们只想让目的地址为10.142.0.0/16的包走代理,那以,添加如下的iptables规则

$ iptables -t nat -A OUTPUT -d 10.142.0.0/16 -p tcp -j REDIRECT --to-ports 8881

Reference

Last updated