feat: 添加启用ipv6转发

This commit is contained in:
耗子
2026-02-11 19:37:20 +08:00
parent e3742e61d8
commit de5d76bff6
2 changed files with 8 additions and 1 deletions
+6
View File
@@ -4,6 +4,7 @@ import (
"cmp"
"errors"
"fmt"
"os"
"regexp"
"slices"
"strings"
@@ -271,6 +272,11 @@ func (r *firewalld) Forward(rule Forward, operation Operation) error {
return err
}
// 启用 IP 转发
_, _ = shell.Execf("sysctl -w net.ipv4.ip_forward=1")
_, _ = shell.Execf("sysctl -w net.ipv6.conf.all.forwarding=1")
_ = os.WriteFile("/etc/sysctl.d/99-acepanel-forward.conf", []byte("net.ipv4.ip_forward=1\nnet.ipv6.conf.all.forwarding=1\n"), 0644)
for _, protocol := range buildProtocols(rule.Protocol) {
var ruleBuilder strings.Builder
ruleBuilder.WriteString(fmt.Sprintf("firewall-cmd --zone=public --%s-forward-port=port=%d:proto=%s:", operation, rule.Port, protocol))
+2 -1
View File
@@ -391,7 +391,8 @@ func (r *ufw) Forward(rule Forward, operation Operation) error {
func (r *ufw) addForward(rule Forward) error {
// 启用 IP 转发
_, _ = shell.Execf("sysctl -w net.ipv4.ip_forward=1")
_ = os.WriteFile("/etc/sysctl.d/99-acepanel-forward.conf", []byte("net.ipv4.ip_forward=1\n"), 0644)
_, _ = shell.Execf("sysctl -w net.ipv6.conf.all.forwarding=1")
_ = os.WriteFile("/etc/sysctl.d/99-acepanel-forward.conf", []byte("net.ipv4.ip_forward=1\nnet.ipv6.conf.all.forwarding=1\n"), 0644)
content, err := os.ReadFile(beforeRulesPath)
if err != nil {