Skip to content

Commit 18ab9c7

Browse files
committed
fix bash shell bug
1 parent 0de8639 commit 18ab9c7

File tree

5 files changed

+115
-43
lines changed

5 files changed

+115
-43
lines changed

GFlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
216.58.194.99
2+
180.97.33.107

Home.md

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 90 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,101 @@
1-
# intelliq-redsocks
2-
实现Linux下的全局翻墙,使用redsocks配合iptables实现请求流量的转发,详细参见[此处Github主页](https://github.com/darkk/redsocks)
1+
# 一、简介
32

4-
## 一、使用方法
3+
实现Linux下的全局翻墙,使用redsocks配合iptables实现请求流量的转发
54

6-
1. 安装依赖包
75

8-
yum install libevent libevent-deve
96

10-
2. 启动myredsocks
117

12-
./myredsocks.sh star
8+
有的时候在实验环境中下载一些被`GFW`给墙掉的资源会出现下载不到的情况,好在网上有大神使用`C`写了一个库可以将将本地的流量从一个端口转向`Socket5`的端口,我们在使用一个`SSH -D`参数本地启动一个`Socket5`端口,使用`redsocks`将流量转到对应的`Socket5`上。这样就是就可以实现任何流量都可以翻墙了,由于官方的`redsocks`并没有提供`iptables`的配置方法,所以我写了一个脚本,自动的读取配置文件啥的,帮助快速使用。
9+
10+
感谢大神的项目,详细参见[此处Github主页](https://github.com/darkk/redsocks)
11+
12+
# 一、使用方法
13+
14+
本人已经针对`redsocks`的一个稳定版本编译好了一个直接可以运行的二进制文件,在`Centos`上可以直接使用。如果想编译其他`Linux`版本上的请按照`redsocks`官方文档操作
15+
16+
17+
18+
1. 使用前请安装依赖包
19+
如果是`Centos`操作系统
20+
```bash
21+
Shell> yum install libevent libevent-deve
22+
```
23+
如果是`Ubuntu`操作系统
24+
```bash
25+
Shell> sudo apt-get install libevent-2.0-5 libevent-dev
26+
27+
```
28+
29+
2. 启动myredsocks
30+
```bash
31+
Shell > ./myredsocks.sh start #启动服务进程
32+
start the redsocks........................
33+
please tell me you sock_server:127.0.0.1 #输入socket5代理服务器的地址
34+
please tell me you sock_port:7070 #输入socket5代理服务器的端口
35+
```
1336

1437
3. 选择代理模式
1538

16-
./myredsocks.sh proxyall|prox
39+
**全局代理模式**
40+
41+
42+
```bash
43+
./myredsocks.sh proxyall #启动全局代理模式,此模式下将代理所有的访问
44+
please tell me you network:192.168.188.0/24 #输入你当前主机的网络信息,因为该网段的机器是不需要翻墙访问的
45+
your iptabls OUTPUT chain like this....
46+
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
47+
num pkts bytes target prot opt in out source destination
48+
49+
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
50+
num pkts bytes target prot opt in out source destination
51+
52+
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
53+
num pkts bytes target prot opt in out source destination
54+
1 0 0 RETURN tcp -- * * 0.0.0.0/0 192.168.188.0/24
55+
2 0 0 RETURN tcp -- * * 0.0.0.0/0 127.0.0.1
56+
3 0 0 RETURN tcp -- * * 0.0.0.0/0 127.0.0.1
57+
4 0 0 REDIRECT tcp -- * * 0.0.0.0/0 0.0.0.0/0 redir ports 12345
58+
59+
Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
60+
num pkts bytes target prot opt in out source destination
61+
```
62+
63+
**代理指定主机**
64+
65+
该模式下只代理`GFlist.txt`中指定的主机
66+
67+
```bash
68+
Shell> ./myredsocks.sh proxy
69+
please tell me you network:192.168.188.0/24 #输入你的网络信息,通全局代理模式一样,同网段的机器不要翻墙
70+
this ip[216.58.194.99] will use proxy connected ....
71+
this ip[180.97.33.107] will use proxy connected ....
72+
your iptabls OUTPUT chain like this....
73+
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
74+
num pkts bytes target prot opt in out source destination
75+
76+
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
77+
num pkts bytes target prot opt in out source destination
78+
79+
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
80+
num pkts bytes target prot opt in out source destination
81+
1 0 0 RETURN tcp -- * * 0.0.0.0/0 192.168.188.0/24
82+
2 0 0 RETURN tcp -- * * 0.0.0.0/0 127.0.0.1
83+
3 0 0 RETURN tcp -- * * 0.0.0.0/0 127.0.0.1
84+
4 0 0 REDIRECT tcp -- * * 0.0.0.0/0 216.58.194.99 redir ports 12345
85+
5 0 0 REDIRECT tcp -- * * 0.0.0.0/0 180.97.33.107 redir ports 12345
86+
87+
Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
88+
num pkts bytes target prot opt in out source destination
89+
90+
```
91+
92+
4. 清理代理与关闭代理
93+
94+
95+
```bash
1796

97+
Shell> ./myredsocks.sh clean #清理所有的代理模式
98+
Shell> ./myredsocks.sh stop #关闭代理
1899

19-
4. 清理代理
20100

21-
./myredsocks.sh clean
101+
```

myredsocks.sh

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
#!/bin/bash
2+
LINE="==============================================="
3+
OSTYPE=$(cat /etc/os-release | grep -E "^NAME=.*" | awk -F\" '{print $2}')
4+
sock_server="127.0.0.1" #socket5代理服务器
5+
sock_port="7070" #socket5代理端口
6+
proxy_port="12345" #redsock的监听端口
7+
28

3-
proxy_server="192.168.149.150"
4-
proxy_ip=""
5-
proxy_port="12345"
69

710
redsocks_pid="/tmp/redsocks.pid"
811
function start_redsocks()
912
{
10-
1113
echo "start the redsocks........................"
1214
if [[ -f ${redsocks_pid} ]];then
13-
echo "the redsocks is stared......"
15+
echo "the redsocks is stared..................."
1416
return 0
1517
fi
18+
rm -rf redsocks.conf
19+
cp redsocks.conf.example redsocks.conf
20+
read -p "please tell me you sock_server:" sock_server
21+
read -p "please tell me you sock_port:" sock_port
22+
sed -i '18s/daemon.*/daemon = on;/g' redsocks.conf
23+
sed -i '44s/local_port.*/local_port = '${proxy_port}';/g' redsocks.conf
24+
sed -i '61s/ip.*/ip = '${sock_server}';/g' redsocks.conf
25+
sed -i '62s/port.*/port = '${sock_port}';/g' redsocks.conf
1626
./redsocks -c redsocks.conf -p ${redsocks_pid}
1727
}
1828
function stop_redsocks()
@@ -31,10 +41,8 @@ function restart_redsocks()
3141
stop_redsocks
3242
start_redsocks
3343
}
34-
3544
until [ $# -eq 0 ]
3645
do
37-
3846
case $1 in
3947
start)
4048
start_redsocks
@@ -55,6 +63,10 @@ do
5563
proxy)
5664
#proxy the fwlist.txt
5765
iptables -t nat -F
66+
read -p "please tell me you network:" mynetwork
67+
iptables -t nat -A OUTPUT -p tcp -d ${mynetwork} -j RETURN
68+
iptables -t nat -A OUTPUT -p tcp -d ${sock_server} -j RETURN
69+
iptables -t nat -A OUTPUT -p tcp -d 127.0.0.1 -j RETURN
5870
while read line
5971
do
6072
echo -e "\033[32m this ip[${line}] will use proxy connected .... \033[0m"
@@ -67,9 +79,9 @@ do
6779
proxyall)
6880
#proxy all connection
6981
iptables -t nat -F
70-
read -p "please tell me you network..." mynetwork
82+
read -p "please tell me you network:" mynetwork
7183
iptables -t nat -A OUTPUT -p tcp -d ${mynetwork} -j RETURN
72-
iptables -t nat -A OUTPUT -p tcp -d ${proxy_server} -j RETURN
84+
iptables -t nat -A OUTPUT -p tcp -d ${sock_server} -j RETURN
7385
iptables -t nat -A OUTPUT -p tcp -d 127.0.0.1 -j RETURN
7486
iptables -t nat -A OUTPUT -p tcp -j REDIRECT --to-ports ${proxy_port}
7587
echo -e "\033[32m your iptabls OUTPUT chain like this.... \033[0m"

redsocks.conf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ base {
1010
* "file:/path/to/file"
1111
* syslog:FACILITY facility is any of "daemon", "local0"..."local7"
1212
*/
13-
log = "file:/tmp/redsocks.log";
13+
log = stderr;
1414
// log = "file:/path/to/file";
1515
// log = "syslog:local7";
1616

@@ -40,7 +40,7 @@ redsocks {
4040
* use 0.0.0.0 if you want to listen on every interface.
4141
* `local_*' are used as port to redirect to.
4242
*/
43-
local_ip = 0.0.0.0;
43+
local_ip = 127.0.0.1;
4444
local_port = 12345;
4545

4646
// listen() queue length. Default value is SOMAXCONN and it should be
@@ -58,7 +58,7 @@ redsocks {
5858
// `ip' and `port' are IP and tcp-port of proxy-server
5959
// You can also use hostname instead of IP, only one (random)
6060
// address of multihomed host will be used.
61-
ip = 192.168.149.150;
61+
ip = 127.0.0.1;
6262
port = 7070;
6363

6464

0 commit comments

Comments
 (0)