feat: add virtual subnet forwarding rules

This commit is contained in:
chick
2026-06-02 23:10:58 +08:00
parent de87a8085b
commit e0d715a593
2 changed files with 39 additions and 2 deletions
+20 -1
View File
@@ -6,6 +6,9 @@
- 开启 IPv4 转发:`/proc/sys/net/ipv4/ip_forward = 1`
- 允许 `192.168.2.0/24``192.168.3.0/24` 双向转发
- 允许 `192.168.2.0/24``192.168.3.0/24` 主动访问虚拟组网 `192.168.4.0/24`
- 允许 `192.168.4.0/24``192.168.2.0/24``192.168.3.0/24` 的 RELATED/ESTABLISHED 回包
- 禁止 `192.168.4.0/24` 主动访问 `192.168.2.0/24``192.168.3.0/24`,实现安全隔离
- 允许 `tun0` 入站/出站 FORWARD
- 开机延迟 `20s` 执行
@@ -25,7 +28,7 @@ curl -fsSL https://gitea.chickliu.fun/Hermes/fnos-iptables-forward/raw/branch/ma
## 自定义网段 / 网卡 / 延迟
```bash
sudo LAN_A=192.168.2.0/24 LAN_B=192.168.3.0/24 TUN_IF=tun0 DELAY=20s bash install.sh install
sudo LAN_A=192.168.2.0/24 LAN_B=192.168.3.0/24 VIRTUAL_LAN=192.168.4.0/24 TUN_IF=tun0 DELAY=20s bash install.sh install
```
## 查看状态
@@ -66,8 +69,24 @@ set -Eeuo pipefail
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -F FORWARD
iptables -P FORWARD ACCEPT
# 放行 192.168.3.0/24 <-> 192.168.2.0/24
iptables -A FORWARD -s 192.168.2.0/24 -d 192.168.3.0/24 -j ACCEPT
iptables -A FORWARD -s 192.168.3.0/24 -d 192.168.2.0/24 -j ACCEPT
# 放行 192.168.3.0/24、192.168.2.0/24 -> 192.168.4.0/24(虚拟组网)
iptables -A FORWARD -s 192.168.3.0/24 -d 192.168.4.0/24 -j ACCEPT
iptables -A FORWARD -s 192.168.2.0/24 -d 192.168.4.0/24 -j ACCEPT
# 放行 192.168.4.0/24 -> 192.168.3.0/24、192.168.2.0/24 的回包(必须)
iptables -A FORWARD -s 192.168.4.0/24 -d 192.168.3.0/24 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -s 192.168.4.0/24 -d 192.168.2.0/24 -m state --state RELATED,ESTABLISHED -j ACCEPT
# 禁止 192.168.4.0/24 主动访问 192.168.3.0/24、192.168.2.0/24(安全隔离)
iptables -A FORWARD -s 192.168.4.0/24 -d 192.168.3.0/24 -j DROP
iptables -A FORWARD -s 192.168.4.0/24 -d 192.168.2.0/24 -j DROP
# 放行 EasyTier 虚拟网卡 tun0
iptables -A FORWARD -i tun0 -j ACCEPT
iptables -A FORWARD -o tun0 -j ACCEPT
```