Closed zkryakgul closed 4 years ago
I suspect something's not quite right when you create your rule. This should work if you want the add the same rule as you did via the command line:
import iptc
t = iptc.Table('nat')
c = iptc.Chain(t, 'PREROUTING')
r = iptc.Rule()
r.protocol = 'tcp'
r.dst = '192.168.0.1'
r.match = r.create_match('tcp')
r.match.dport = '80'
r.target = r.create_target('DNAT')
r.target.to_destination = '192.168.0.100:443'
c.insert_rule(r)
yes it's works. I checked my code again and realize i forgot the set protocol parameter to my rule. I think that was the problem. Thanks!
Using normal iptables commands you can do something like that:
iptables -t nat -A PREROUTING -p tcp -m tcp -d 192.168.0.1 --dport 80 -j DNAT --to-destination 192.168.0.100:443
But when i create a new Target and try to set parameter to it it raises an error:
Traceback: