redsocks2 自动代理设置

本文涉及的产品
公网NAT网关,每月750个小时 15CU
简介:

redsock2 可以把一些不支持透明代理的代理服务器重定向一下,这样可以实现透明代理了


redsock2安装很简单直接make就可以了,

ubuntu需要 

1
apt-get intsll libevent-2.0-5 libssl-dev

安装完成后,直接把 redsocks2 复制到相关目录即可。


我这用它做网关, 然后测试了一下,http 和 https 不能一起走,要分开

redsocks2 配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
base {
   log_debug = off; 
   log_info = off;
   daemon = on;
   redirector= iptables;
}
 
redsocks {
  local_ip = 192.168.1.1;
  local_port = 1080;
  ip = 192.168.1.1;
  port = 8787;
  type  = http-relay;
  timeout = 12;
  autoproxy = 1;
}
 
redsocks {
  local_ip = 192.168.1.1;
  local_port = 1081;
  ip = 192.168.1.1;
  port = 8787;
  type  = http-connect;
  timeout = 12;
  autoproxy = 1;
}
 
redsocks {
  local_ip = 192.168.1.1;
  local_port = 1090;
  interface = eth0;
  type  = direct;     #主要用来解决NAT问题,让WAN可以访问到LAN
  timeout = 1;
  autoproxy = 0;
}
 
autoproxy {
  no_quick_check_seconds = 300;
  quick_connect_timeout = 2;
}
 
ipcache {
  cache_size = 4;
  cache_file =  "/home/user/conf/cache.ip" ;
  stale_time = 7200;
  autosave_interval = 3600;
  port_check = 1;
}

相关iptables 设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
 
iptables-restore< /etc/network/iptables .up.rules
 
iptables -t nat -N RSHTTPS
iptables -t nat -A RSHTTPS -o lo -j RETURN
iptables -t nat -A RSHTTPS -d 0.0.0.0 /8  -j RETURN
iptables -t nat -A RSHTTPS -d 10.0.0.0 /8  -j RETURN
iptables -t nat -A RSHTTPS -d 127.0.0.0 /8  -j RETURN
iptables -t nat -A RSHTTPS -d 169.254.0.0 /16  -j RETURN
iptables -t nat -A RSHTTPS -d 172.16.0.0 /12  -j RETURN
iptables -t nat -A RSHTTPS -d 172.17.0.0 /12  -j RETURN
iptables -t nat -A RSHTTPS -d 192.168.0.0 /16  -j RETURN
iptables -t nat -A RSHTTPS -d 224.0.0.0 /4  -j RETURN
iptables -t nat -A RSHTTPS -d 240.0.0.0 /4  -j RETURN
iptables -t nat -A RSHTTPS -p tcp -j REDIRECT --to-port 1081
iptables -t nat -I PREROUTING -p tcp --dport 443 -j RSHTTPS
 
iptables -t nat -N RSHTTP
iptables -t nat -A RSHTTP -o lo -j RETURN
iptables -t nat -A RSHTTP -d 0.0.0.0 /8  -j RETURN
iptables -t nat -A RSHTTP -d 10.0.0.0 /8  -j RETURN
iptables -t nat -A RSHTTP -d 127.0.0.0 /8  -j RETURN
iptables -t nat -A RSHTTP -d 169.254.0.0 /16  -j RETURN
iptables -t nat -A RSHTTP -d 172.16.0.0 /12  -j RETURN
iptables -t nat -A RSHTTP -d 172.17.0.0 /12  -j RETURN
iptables -t nat -A RSHTTP -d 192.168.0.0 /16  -j RETURN
iptables -t nat -A RSHTTP -d 224.0.0.0 /4  -j RETURN
iptables -t nat -A RSHTTP -d 240.0.0.0 /4  -j RETURN
iptables -t nat -A RSHTTP -p tcp -j REDIRECT --to-port 1080
iptables -t nat -I PREROUTING -p tcp --dport 80 -j RSHTTP
 
iptables -t nat -N RSDIRECT
iptables -t nat -A RSDIRECT -p tcp -j REDIRECT --to-port 1090
iptables -t nat -I PREROUTING -p tcp -d 208.67.220.220 -j RSDIRECT
#不加下面这条,没办法WAN网连接进来
iptables -t nat -I PREROUTING -p tcp -s 192.168.1.2 --sport 3389 -j RSDIRECT
 
 
pkill redsocks2
redsocks2 -c  /home/tool/conf/red .conf


还有另一个叫 cow 的软件也可以实现类似效果。功能上更加强点。



本文转自 nonono11 51CTO博客,原文链接:http://blog.51cto.com/abian/1787673,如需转载请自行联系原作者

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
基于阿里云,构建一个企业web应用上云经典架构,让IT从业者体验企业级架构的实战训练。
相关文章
|
10月前
|
Web App开发 数据安全/隐私保护
如何在AdsPower中设置易路代理YiLuProxy?
如何在AdsPower中设置易路代理YiLuProxy?
169 0
|
6天前
|
弹性计算 运维 Shell
自动配置rsynd
【4月更文挑战第29天】
14 0
|
16天前
|
JavaScript 前端开发 网络安全
全局代理与自动代理主要差异与选择
全局代理与自动代理主要差异与选择
33 12
|
17天前
|
安全 Linux 数据安全/隐私保护
代理ip全局代理是什么且如何设置
代理ip全局代理是什么且如何设置
|
16天前
如何自动获取、验证和使用代理IP
如何自动获取、验证和使用代理IP
|
16天前
|
Python
如何动态切换代理IP
如何动态切换代理IP
|
16天前
|
数据挖掘 Python
如何将动态IP代理转换为静态IP代理的方法与步骤
如何将动态IP代理转换为静态IP代理的方法与步骤
|
16天前
|
负载均衡 网络协议 数据安全/隐私保护
详解配置代理和IP设置的含义
详解配置代理和IP设置的含义
|
20天前
|
数据采集 安全 大数据
使用代理IP时有哪些小技巧?
代理IP工具在大数据和跨境行业广泛使用,能隐藏真实IP并提升数据采集效率。选择时考虑代理IP的质量、速度、稳定性和价格,确保服务商信誉安全。测试多个代理IP以满足不同需求,设置正确请求头信息避免被目标服务器屏蔽。避免频繁更换地区,定期更新代理IP,并保护个人信息。根据业务需求制定使用计划,提前学习相关技巧,可避免后期问题。
|
8月前
|
安全 大数据
什么是高匿代理,与普匿和透明代理的区别是什么?它有什么作用?
什么是高匿代理,与普匿和透明代理的区别是什么?它有什么作用?