Skip to content

Commit

Permalink
iptables 添加注释
Browse files Browse the repository at this point in the history
  • Loading branch information
bjdgyc committed Feb 26, 2024
1 parent 5a331e2 commit 3c8d0c6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions server/handler/link_tun.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,21 @@ func checkTun() {
base.CheckModOrLoad("iptable_filter")
base.CheckModOrLoad("iptable_nat")

// 添加注释
natRule := []string{"-s", base.Cfg.Ipv4CIDR, "-o", base.Cfg.Ipv4Master, "-m", "comment",
"--comment", "anylink tun nat", "-j", "MASQUERADE"}
if natExists, _ := ipt.Exists("nat", "POSTROUTING", natRule...); !natExists {
ipt.Insert("nat", "POSTROUTING", 1, natRule...)
err = ipt.InsertUnique("nat", "POSTROUTING", 1, natRule...)
if err != nil {
base.Error(err)
}

// 添加注释
forwardRule := []string{"-m", "comment", "--comment", "anylink forward filter", "-j", "ACCEPT"}
if forwardExists, _ := ipt.Exists("filter", "FORWARD", forwardRule...); !forwardExists {
ipt.Insert("filter", "FORWARD", 1, forwardRule...)
err = ipt.InsertUnique("filter", "FORWARD", 1, forwardRule...)
if err != nil {
base.Error(err)
}

base.Info(ipt.List("nat", "POSTROUTING"))
base.Info(ipt.List("filter", "FORWARD"))
}
Expand Down

0 comments on commit 3c8d0c6

Please sign in to comment.