mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-22 00:19:39 +08:00
added iptables check cmd
This commit is contained in:
@@ -110,16 +110,19 @@ func iptablesPortForward(entry string, inport string, outport string, isIP bool)
|
|||||||
return errors.New("could not locate ip for " + entry)
|
return errors.New("could not locate ip for " + entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := ncutils.RunCmd("iptables -t nat -A PREROUTING -p tcp --dport "+inport+" -j DNAT --to-destination "+address+":"+outport, false)
|
if output, _ := ncutils.RunCmd("iptables -t nat -C PREROUTING -p tcp --dport "+inport+" -j DNAT --to-destination "+address+":"+outport, false); output == "" {
|
||||||
if err != nil {
|
_, err := ncutils.RunCmd("iptables -t nat -A PREROUTING -p tcp --dport "+inport+" -j DNAT --to-destination "+address+":"+outport, false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = ncutils.RunCmd("iptables -t nat -A PREROUTING -p udp --dport "+inport+" -j DNAT --to-destination "+address+":"+outport, false)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = ncutils.RunCmd("iptables -t nat -A POSTROUTING -j MASQUERADE", false)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = ncutils.RunCmd("iptables -t nat -A PREROUTING -p udp --dport "+inport+" -j DNAT --to-destination "+address+":"+outport, false)
|
return nil
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
_, err = ncutils.RunCmd("iptables -t nat -A POSTROUTING -j MASQUERADE", false)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if running in host networking mode, run iptables to map to CoreDNS container
|
// if running in host networking mode, run iptables to map to CoreDNS container
|
||||||
|
Reference in New Issue
Block a user