func TeardownIPMasq(ipn *net.IPNet, chain string, comment string) error {
	ipt, err := iptables.New()
	if err != nil {
		return fmt.Errorf("failed to locate iptables: %v", err)
	}
	if err = ipt.Delete("nat", "POSTROUTING", "-s", ipn.String(), "-j", chain, "-m", "comment", "--comment", comment); err != nil {
		return err
	}
	if err = ipt.ClearChain("nat", chain); err != nil {
		return err
	}
	return ipt.DeleteChain("nat", chain)
}
TeardownIPMasq undoes the effects of SetupIPMasq
package ip
import (
	"fmt"
	"net"
	"github.com/coreos/go-iptables/iptables"
)
func SetupIPMasq(ipn *net.IPNet, chain string, comment string) error {
	ipt, err := iptables.New()
	if err != nil {
		return fmt.Errorf("failed to locate iptables: %v", err)
	}
	if err = ipt.NewChain("nat", chain); err != nil {
		if err.(*iptables.Error).ExitStatus() != 1 {
			return err
		}
	}
	if err = ipt.AppendUnique("nat", chain, "-d", ipn.String(), "-j", "ACCEPT", "-m", "comment", "--comment", comment); err != nil {
		return err
	}
	if err = ipt.AppendUnique("nat", chain, "!", "-d", "224.0.0.0/4", "-j", "MASQUERADE", "-m", "comment", "--comment", comment); err != nil {
		return err
	}
	return ipt.AppendUnique("nat", "POSTROUTING", "-s", ipn.String(), "-j", chain, "-m", "comment", "--comment", comment)
}