dospin/net_linux.go

33 lines
1.2 KiB
Go
Raw Normal View History

2016-02-26 17:35:57 -06:00
/*
2017-01-25 17:59:25 -06:00
Copyright 2016-2017 gtalent2@gmail.com
2016-02-26 17:35:57 -06:00
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
2016-02-14 23:38:28 -06:00
package main
import (
"log"
2016-02-27 18:15:37 -06:00
"os/exec"
2016-02-14 23:38:28 -06:00
)
func addPortForward(ruleName, gatewayInt, localIp, targetIp, port string) {
log.Println("Setting up port", port, "to", targetIp)
cmdOut, err := exec.Command("iptables", "-A", "PREROUTING", "-t", "nat", "-i", "\""+gatewayInt+"\"", "-p", "tcp", "--dport", port, "-j", "DNAT", "--to", targetIp+":"+port).Output()
log.Println("iptables", "-A", "PREROUTING,", "-t", "nat", "-i", "\""+gatewayInt+"\"", "-p", "tcp", "--dport", port, "-j", "DNAT", "--to", targetIp+":"+port)
if err != nil {
log.Println("iptables error:", err)
}
cmdOut, err = exec.Command("iptables", "-A", "FORWARD", "-p", "tcp", "-d", targetIp, "--dport", port, "-j", "ACCEPT").Output()
log.Println("iptables", "-A", "FORWARD", "-p", "tcp", "-d", targetIp, "--dport", port, "-j", "ACCEPT")
if err != nil {
log.Println("iptables error:", err)
}
}
func rmPortForward(ruleName string) {
2016-02-14 23:38:28 -06:00
log.Print("Port forwarding not currently implemented for Linux/iptables")
}