redsocks 配合iptables设置全局sockts5代理
参照:http://kuaile.in/archives/1370
架构图:

第一步,安装redsocks
1. 安装依赖
yum install libevent-devel
2. 下载编译
git clone https://github.com/darkk/redsocks
cd redsocks
make
3. 配置
将redsocks源码目录下的redsocks.conf.example复制为redsocks.conf,编辑redsocks.conf
base {
// debug: connection progress & client list on SIGUSR1
log_debug = on;
// info: start and end of client session
log_info = on;
/* possible `log' values are:
* stderr
* "file:/path/to/file"
* syslog:FACILITY facility is any of "daemon", "local0"..."local7"
*/
log = stderr;
// log = "file:/path/to/file";
// log = "syslog:local7";
// detach from console
daemon = off;
/* Change uid, gid and root directory, these options require root
* privilegies on startup.
* Note, your chroot may requre /etc/localtime if you write log to syslog.
* Log is opened before chroot & uid changing.
*/
// user = nobody;
// group = nobody;
// chroot = "/var/chroot";
/* possible `redirector' values are:
* iptables - for Linux
* ipf - for FreeBSD
* pf - for OpenBSD
* generic - some generic redirector that MAY work
*/
redirector = iptables;
}
redsocks {
/* `local_ip' defaults to 127.0.0.1 for security reasons,
* use 0.0.0.0 if you want to listen on every interface.
* `local_*' are used as port to redirect to.
*/
local_ip = 127.0.0.1;
local_port = ; //记住这个端口,这个是redsocks运行的端口
// listen() queue length. Default value is SOMAXCONN and it should be
// good enough for most of us.
// listenq = 128; // SOMAXCONN equals 128 on my Linux box.
// `max_accept_backoff` is a delay to retry `accept()` after accept
// failure (e.g. due to lack of file descriptors). It's measured in
// milliseconds and maximal value is 65535. `min_accept_backoff` is
// used as initial backoff value and as a damper for `accept() after
// close()` logic.
// min_accept_backoff = 100;
// max_accept_backoff = 60000;
// `ip' and `port' are IP and tcp-port of proxy-server
// You can also use hostname instead of IP, only one (random)
// address of multihomed host will be used.
ip = 127.0.0.1; //这个是代-理服务器的端口,如果你本地运行shadows,需要将ip设置为127.0.0.1
port = ; //编辑这个端口值,修改为本地shadowsocks运行的端口
// known types: socks4, socks5, http-connect, http-relay
type = socks5;
// login = "foobar";
// password = "baz";
}
redudp {
// `local_ip' should not be 0.0.0.0 as it's also used for outgoing
// packets that are sent as replies - and it should be fixed
// if we want NAT to work properly.
local_ip = 127.0.0.1;
local_port = ;
// `ip' and `port' of socks5 proxy server.
ip = 10.0.0.1;
port = ;
login = username;
password = pazzw0rd;
// redsocks knows about two options while redirecting UDP packets at
// linux: TPROXY and REDIRECT. TPROXY requires more complex routing
// configuration and fresh kernel (>= 2.6.37 according to squid
// developers[1]) but has hack-free way to get original destination
// address, REDIRECT is easier to configure, but requires `dest_ip` and
// `dest_port` to be set, limiting packet redirection to single
// destination.
// [1] http://wiki.squid-cache.org/Features/Tproxy4
dest_ip = 8.8.8.8;
dest_port = ;
udp_timeout = ;
udp_timeout_stream = ;
}
dnstc {
// fake and really dumb DNS server that returns "truncated answer" to
// every query via UDP, RFC-compliant resolver should repeat same query
// via TCP in this case.
local_ip = 127.0.0.1;
local_port = ;
}
// you can add more `redsocks' and `redudp' sections if you need.
4. 运行
./redsocks
第二步,配置防火墙
全局代-理是核心就是iptables规则了,这里首先假定 $SERVIER_IP为你的shadowsocks服务器的IP地址
特别注意,这里是你部署过shadowsocks服务器的地址.不是你本地shadowsocks的地址
将以下的shell命令复制粘贴到到bash中即可完成配置:
注意,请使用你的shadowsocks服务器地址替换shell命令中的$SERVER_IP)
#不重定向目的地址为服务器的包
sudo iptables -t nat -A OUTPUT -d $SERVER_IP -j RETURN #请用你的shadowsocks服务器的地址替换$SERVER_IP #不重定向私有地址的流量
sudo iptables -t nat -A OUTPUT -d 10.0.0.0/ -j RETURN
sudo iptables -t nat -A OUTPUT -d 172.16.0.0/ -j RETURN
sudo iptables -t nat -A OUTPUT -d 192.168.0.0/ -j RETURN #不重定向保留地址的流量,这一步很重要
sudo iptables -t nat -A OUTPUT -d 127.0.0.0/ -j RETURN #重定向所有不满足以上条件的流量到redsocks监听的12345端口
sudo iptables -t nat -A OUTPUT -p tcp -j REDIRECT --to-ports #12345是你的redsocks运行的端口,请根据你的情况替换它
接下来,将上面的shell保存为sh脚本,依次运行shadowsocks客户端,redsocks客户端和sh脚本即可.
需要额外说明的是: 如果你关闭了redsocks后,需要将之前配置的iptables规则删除,将下面的shell命令保持为sh脚本,运行即可
#/bin/bash
sudo iptables -t nat -D OUTPUT
sudo iptables -t nat -D OUTPUT
sudo iptables -t nat -D OUTPUT
sudo iptables -t nat -D OUTPUT
sudo iptables -t nat -D OUTPUT
sudo iptables -t nat -D OUTPUT
第三步,配置ssh Tunnel
ssh -C -f -N -g -D user@Tunnel_Host -p ssh_port
第四步,配置pac文件到web服务器
vim sock.pac
function FindProxyForURL(url, host) { return "SOCKS 172.16.1.122:1236"; }
第五步,ios配置使用pac
。。。
redsocks 配合iptables设置全局sockts5代理的更多相关文章
- redsocks 设置全局代理
分享一下我的经验, http://lilydjwg.is-programmer.com/2014/2/7/linux-really-global-http-proxy.42701.html 1. 优点 ...
- Ubuntu「一键」设置全局代理
Ubuntu「一键」设置代理 sonictl note: the DNS problem may be still there. Except proxychains. WSL (Windows Su ...
- Linux设置全局代理与yum代理
设置全局代理,方法如下: 修改 /etc/profile 文件,添加下面内容: http_proxy=http://username:password@yourproxy:8080/ ftp_prox ...
- C#程序中设置全局代理(Global Proxy)
1. HttpWebRequest类的Proxy属性,只要设置了该属性就能够使用代理了,如下: 1 //设置代理 2 WebProxy WP = new Web ...
- [Z] C#程序中设置全局代理(Global Proxy)
https://www.cnblogs.com/Javi/p/7274268.html 1. HttpWebRequest类的Proxy属性,只要设置了该属性就能够使用代理了,如下: 1 ...
- Linux/CentOS设置全局代理(http)
说明:为什么说是http代理,其实这个还不能说是全称走代理,罪名写的区别就是ICMP协议这个设置就无效,只能说是90%的应用都可以使用这个设置来实现代理访问,只有个别不行,比如一些软件根本不走http ...
- 中小研发团队架构实践之生产环境诊断工具WinDbg 三分钟学会.NET微服务之Polly 使用.Net Core+IView+Vue集成上传图片功能 Fiddler原理~知多少? ABP框架(asp.net core 2.X+Vue)模板项目学习之路(一) C#程序中设置全局代理(Global Proxy) WCF 4.0 使用说明 如何在IIS上发布,并能正常访问
中小研发团队架构实践之生产环境诊断工具WinDbg 生产环境偶尔会出现一些异常问题,WinDbg或GDB是解决此类问题的利器.调试工具WinDbg如同医生的听诊器,是系统生病时做问题诊断的逆向分析工具 ...
- 关于nginx安装、iptables设置和查看端口指令netstat/ss
实验1: Nginx介绍 Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP ...
- IT这一行,如可高速下载国外资源之迅雷设置免费SSH代理下载国外资源
本文转自SUN'S BLOG 原文地址:IT这一行,如可高速下载国外资源之迅雷 我们这些做IT这一行的人,经常,下载一些国外的一些资源,可是让人蛋碎的是,往往这些资源下载都慢的像蜗牛,真的让人无法忍受 ...
随机推荐
- OpenGL extension specification (from openGL.org)
Shader read/write/atomic into UAV global memory (need manual sync) http://www.opengl.org/registry/sp ...
- Web 在线文件管理器学习笔记与总结(9)下载文件
① 普通形式的文件可以使用超链接形式下载 <a href = '下载文件名'>点击下载</a> ② 如果下载图片.html 等类型的文件,使用header() 函数发送网页头信 ...
- PHP抓取采集类snoopy介绍
PHP抓取采集类snoopy介绍 一个PHP的抓取方案 在 2011年07月04日 那天写的 已经有 10270 次阅读了 感谢 参考或原文 服务器君一共花费了14.288 ms进行了2次 ...
- [转]LaTeX处女级入门命令语法集
1.LaTeX文件的框架如下: \documentclass{article} \begin{document} This is the body of the article \end{docume ...
- 2014总结&2015计划
2014总结&2015计划 今天是2015/1/1,新的一年终于到来了,昨天老板要求提交2014的工作总结和2015的工作计划,正好提醒我,要总结和计划了. 先回顾2014年初的计划: 新年计 ...
- socketlog
说明 SocketLog适合Ajax调试和API调试, 举一个常见的场景,用SocketLog来做微信调试, 我们在做微信API开发的时候,如果API有bug,微信只提示“改公众账号暂时无法提供服务, ...
- java多线程编程(一基础概念)
1.进程和线程 进程,是一个正在运行的程序实体,windows下常见的就是xxx.exe,在任务管理器中可以看见很多个进程.它是线程的容器. 线程,是进程中的一个执行流.在单线程编程中,我 ...
- Solaris 10下Qt编译Oracle 10g驱动
上回书讲到<Oracle 10g在Solaris 10中安装详解>,现在开始用Qt来编译下Oracle 10g驱动吧!这样就可以通过Qt程序联入Oracle数据库了! Oracle的环境变 ...
- sphinx续5-主索引增量索引和实时索引
原文件地址:http://blog.itpub.net/29806344/viewspace-1400942/ 在数据库数据非常庞大的时候,而且实时有新的数据插入,如果我们不更新索引,新的数据就sea ...
- 用Quartz处理定时执行的任务
这次做的项目中,有一部分功能需要实现定时执行.呃,这样说可能有点笼统,打个比方吧.例如用户在登录的时候,连续输错3次密码后,系统会将该用户冻结,不再允许该用户登录系统,等到了晚上零晨时分,再为所有被冻 ...