linux
  • Introduction
  • Yum
    • 基础yum源的配置
    • 为yum源配置代理
    • Centos指定版本的yum源
    • 环境变量
    • 本地yum源
    • 制作yum源
      • 同步yum源
    • epel源
  • Iptables
    • 基本匹配条件
    • Match-Extensions
      • Addrtype
      • Set
      • TCP
    • Target-Extensions
      • DNAT
      • LOG
    • Iptables规则持久化
    • 连接追踪
  • LVS
    • Ipvsadm命令
  • 磁盘与分区
    • 创建分区
    • 格式化与挂载
    • fstab
    • LVM
      • LVM扩容
    • swap分区
    • tmpfs
  • 网络相关
    • 重命名网卡
    • resolv.conf
    • Tcpdump
    • dig与nslookup
  • Other
    • CPU与内存
    • 进程
      • 僵尸进程
    • SSH密钥登录
    • 用户管理
    • Crontab
  • Nofile
    • 原理
  • 常用软件安装篇
    • MYSQL
    • 系统与内核
      • 指定内核启动
    • NFS
    • Haproxy
    • Keepalived
    • Squid
    • Redsocks
    • Shadowsocks
    • 时钟同步
  • 内存
Powered by GitBook
On this page
  • 1、安装依赖
  • 2、下载源码与编译
  • 3、拷贝到/usr/bin目录下
  • 4、创建配置文件
  • 5、启动
  • 6、添加代理规则
  • Reference

Was this helpful?

  1. 常用软件安装篇

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

PreviousSquidNextShadowsocks

Last updated 5 years ago

Was this helpful?

https://github.com/darkk/redsocks
https://crosp.net/blog/administration/install-configure-redsocks-proxy-centos-linux/
https://www.imzcy.cn/1560.html