def writeRules(deviceName):
    for index in xrange(1, LAST_INDEX + 1):
        cmd = ["iptables", "-A", "PREROUTING", "-t", "nat", "-i", deviceName,
               "-p", "tcp", "--dport", str(sshPortFromHostIndex(index)), "-j", "DNAT",
               "--to", "%s:22" % ipAddressFromHostIndex(index)]
        runCmd(cmd, canFail=False)
    cmd = ["iptables", "-t", "nat", "-A", "POSTROUTING", "-o", deviceName, "-j", 'MASQUERADE']
    runCmd(cmd, canFail=True)
def deleteRules(deviceName):
    for index in xrange(1, LAST_INDEX):
        cmd = ["iptables", '-D', 'PREROUTING', '-t', 'nat', '-i', deviceName,
               "-p", "tcp", "--dport", str(sshPortFromHostIndex(index)), "-j", "DNAT",
               "--to-destination", "%s:22" % ipAddressFromHostIndex(index)]
        runCmd(cmd, canFail=True)
    cmd = ["iptables", "-t", "nat", "-D", "POSTROUTING", "-o", deviceName, "-j", 'MASQUERADE']
    runCmd(cmd, canFail=True)
def deleteRules(interface):
    for index in xrange(1, 4):
        cmd = ["iptables", '-D', 'PREROUTING', '-t', 'nat', '-i', interface,
               "-p", "tcp", "--dport", str(network.sshPortFromHostIndex(index)), "-j", "DNAT",
               "--to-destination", "%s:22" % network.ipAddressFromHostIndex(index)]
        runCmd(cmd, canFail=True)
    cmd = ["iptables", "-t", "nat", "-D", "POSTROUTING", "-o", interface, "-j",
           "MASQUERADE"]
    runCmd(cmd, canFail=True)
def writeRules(interface):
    for index in xrange(1, 4):
        cmd = ["iptables", "-A", "PREROUTING", "-t", "nat", "-i", interface,
               "-p", "tcp", "--dport", str(network.sshPortFromHostIndex(index)), "-j", "DNAT",
               "--to", "%s:22" % network.ipAddressFromHostIndex(index)]
        print " ".join(cmd)
        runCmd(cmd, canFail=False)
    cmd = ["iptables", "-t", "nat", "-A", "POSTROUTING", "-o", interface, "-j",
           "MASQUERADE"]
    runCmd(cmd, canFail=True)
Пример #5
0
 def ipAddress(self):
     return network.ipAddressFromHostIndex(self._index)
Пример #6
0
 def ipAddress(self):
     return network.ipAddressFromHostIndex(self._index)