添加网卡 alias

This commit is contained in:
bjdgyc
2023-10-30 11:38:31 +08:00
parent 6788a875a2
commit 57990d3d2a
3 changed files with 12 additions and 6 deletions

View File

@@ -28,19 +28,19 @@ func checkTun() {
if err != nil {
base.Fatal("testTun err: ", err)
}
//开启服务器转发
// 开启服务器转发
if err := execCmd([]string{"sysctl -w net.ipv4.ip_forward=1"}); err != nil {
base.Fatal(err)
}
if base.Cfg.IptablesNat {
//添加NAT转发规则
// 添加NAT转发规则
ipt, err := iptables.New()
if err != nil {
base.Fatal(err)
return
}
//修复 rockyos nat 不生效
// 修复 rockyos nat 不生效
cmdstr0 := fmt.Sprintln("modprobe -i iptable_filter")
cmdstr1 := fmt.Sprintf("modprobe -i iptable_nat")
err = execCmd([]string{cmdstr0, cmdstr1})
@@ -75,7 +75,8 @@ func LinkTun(cSess *sessdata.ConnSession) error {
// log.Printf("Interface Name: %s\n", ifce.Name())
cSess.SetIfName(ifce.Name())
cmdstr1 := fmt.Sprintf("ip link set dev %s up mtu %d multicast off", ifce.Name(), cSess.Mtu)
cmdstr1 := fmt.Sprintf("ip link set dev %s up mtu %d multicast off alias %s.%s", ifce.Name(), cSess.Mtu,
cSess.Group.Name, cSess.Username)
cmdstr2 := fmt.Sprintf("ip addr add dev %s local %s peer %s/32",
ifce.Name(), base.Cfg.Ipv4Gateway, cSess.IpAddr)
err = execCmd([]string{cmdstr1, cmdstr2})