Skip to content

Commit de3946d

Browse files
committed
forgot the iptables port redirection rules
1 parent 10c3940 commit de3946d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
- [7.1 OpenWRT 路由器](#71-openwrt-路由器)
3939
- [7.2 通过树莓派做旁路网关](#72-通过树莓派做旁路网关)
4040
- [7.3 安装 Clash](#73-安装-clash)
41+
- [7.4 设置 iptables 转发](#74-设置-iptables-转发)
4142
- [8. 其它](#8-其它)
4243
- [8.1 其它方式](#81-其它方式)
4344
- [8.2 搭建脚本](#82-搭建脚本)
@@ -595,6 +596,31 @@ rules:
595596

596597
然后,你就可以把你的上网设备上的 路由网关 和 DNS 服务器都手动地配置成这个网关就好了(OpenWRT应该不用配置了,树莓派的方式需要手动配置一下)
597598

599+
### 7.4 设置 iptables 转发
600+
601+
```
602+
iptables -t nat -N CLASH
603+
iptables -t nat -A CLASH -d 10.0.0.0/8 -j RETURN
604+
iptables -t nat -A CLASH -d 127.0.0.0/8 -j RETURN
605+
iptables -t nat -A CLASH -d 169.254.0.0/16 -j RETURN
606+
iptables -t nat -A CLASH -d 172.16.0.0/12 -j RETURN
607+
iptables -t nat -A CLASH -d 192.168.0.0/16 -j RETURN
608+
iptables -t nat -A CLASH -d 224.0.0.0/4 -j RETURN
609+
iptables -t nat -A CLASH -d 240.0.0.0/4 -j RETURN
610+
iptables -t nat -A CLASH -p tcp -j REDIRECT --to-ports 7892
611+
```
612+
然后,你可以保存一下这些iptables的规则
613+
614+
```
615+
iptables-save > /etc/iptables.up.rules
616+
```
617+
编辑 `//etc/network/if-pre-up.d/iptables`,在网卡启动的时候加载这些规则
618+
619+
```
620+
#!/bin/sh
621+
/sbin/iptables-restore < /etc/iptables.up.rules
622+
```
623+
然后,再 `chmod +x /etc/network/if-pre-up.d/iptables` 加上可执行权限就好了。
598624

599625
## 8. 其它
600626

0 commit comments

Comments
 (0)