From ef5cad6c7af503127bb9ec2771acb97dfd73c52b Mon Sep 17 00:00:00 2001 From: wsczx Date: Thu, 24 Nov 2022 14:51:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=A4=BA=E4=BE=8B=EF=BC=8C=E6=B7=BB=E5=8A=A0nat?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=B1=95=E7=A4=BA=EF=BC=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?iptables=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/conf/server-sample.toml | 2 ++ server/conf/server.toml | 3 ++- server/handler/link_tun.go | 6 ++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/server/conf/server-sample.toml b/server/conf/server-sample.toml index 785e901..cada39b 100644 --- a/server/conf/server-sample.toml +++ b/server/conf/server-sample.toml @@ -75,5 +75,7 @@ audit_interval = -1 show_sql = false +#是否自动添加nat +iptables_nat = false diff --git a/server/conf/server.toml b/server/conf/server.toml index 45e6d10..e7f274b 100644 --- a/server/conf/server.toml +++ b/server/conf/server.toml @@ -33,4 +33,5 @@ ipv4_gateway = "192.168.10.1" ipv4_start = "192.168.10.100" ipv4_end = "192.168.10.200" - +#是否自动添加nat +iptables_nat = false diff --git a/server/handler/link_tun.go b/server/handler/link_tun.go index 5bd0ebc..5ab2fef 100644 --- a/server/handler/link_tun.go +++ b/server/handler/link_tun.go @@ -40,12 +40,14 @@ func checkTun() { } natRule := []string{"-s", base.Cfg.Ipv4CIDR, "-o", base.Cfg.Ipv4Master, "-j", "MASQUERADE"} forwardRule := []string{"-j", "ACCEPT"} - if natExists, _ := ipt.Exists("filter", "FORWARD", forwardRule...); !natExists { + if natExists, _ := ipt.Exists("nat", "POSTROUTING", natRule...); !natExists { ipt.Insert("nat", "POSTROUTING", 1, natRule...) } - if forwardExists, _ := ipt.Exists("filter", "FORWARD", natRule...); !forwardExists { + if forwardExists, _ := ipt.Exists("filter", "FORWARD", forwardRule...); !forwardExists { ipt.Insert("filter", "FORWARD", 1, forwardRule...) } + base.Info(ipt.List("nat", "POSTROUTING")) + base.Info(ipt.List("filter", "FORWARD")) } }