Closed castaway2000 closed 3 years ago
You can use something like this with the easy module
iptc.easy.add_rule('mangle', 'PREROUTING', {'in-interface': 'eth0', 'target': {'TEE': {'gateway': '192.168.1.100'}}})
In your example you are just missing adding the gateway attribute to the target:
import iptc
table = iptc.Table(iptc.Table.MANGLE)
chain = iptc.Chain(table, "PREROUTING")
rule = iptc.Rule()
rule.in_interface = "eth0"
rule.target = iptc.Target(rule, "TEE")
# This bit was missing
rule.target.gateway='192.168.1.100'
chain.insert_rule(rule)
In your example you are just missing adding the gateway attribute to the target:
import iptc table = iptc.Table(iptc.Table.MANGLE) chain = iptc.Chain(table, "PREROUTING") rule = iptc.Rule() rule.in_interface = "eth0" rule.target = iptc.Target(rule, "TEE") # This bit was missing rule.target.gateway='192.168.1.100' chain.insert_rule(rule)
I wonder why this process didnt work for me i tried this for a few hours last night. I ended up using the following solution after looking at some other kinds of examples using the set_parameter method.
target = iptc.Target(rule, "TEE") target.set_parameter("gateway", "192.168.1.1")
Closing this based on the feedback, thanks @jllorente for helping out.
How would I implement the gateway parameter with this code snip? Cant seem to add it in. Should I convert this to a dictionary process?
The above code fails silently and does not register in iptables
According the docs from iptables for TEE forwarding state that it should be there as it is required for TEE to work and it looks like this example on superuser backs it up. Can you confirm how to do this?