1

I am trying to create the following rule using the python-iptables library.

  # iptables -t nat -A OUTPUT -p tcp -m owner --uid-owner username -j DROP

Here is my code

chain = iptc.Chain(iptc.Table(iptc.Table.NAT), "OUTPUT")
rule = iptc.Rule()
rule.protocol = "tcp"
match = iptc.Match(rule, "owner")
match.uid_owner = "username"
rule.target = iptc.Target(rule, "DROP")
rule.add_match(match)

And I get the following error

    match.uid_owner = "username"
  File "/usr/lib64/python2.7/site-packages/iptc/ip4tc.py", line 455, in __setattr__
    self.parse(name.replace("_", "-"), value)
  File "/usr/lib64/python2.7/site-packages/iptc/ip4tc.py", line 332, in parse
    self._parse(argv, inv, entry)
  File "/usr/lib64/python2.7/site-packages/iptc/ip4tc.py", line 600, in _parse
    self._orig_parse, self._orig_options)
  File "/usr/lib64/python2.7/site-packages/iptc/xtables.py", line 856, in new
    return fn(*args)
  File "/usr/lib64/python2.7/site-packages/iptc/xtables.py", line 1155, in parse_match
    m.name, len(argv) > 1 and argv[1] or "", rv))
iptc.xtables.XTablesError: owner: parameter 'username' error -2

How can I add such rules using this library ?

1 Answers1

0

Problem is solved, the issue was incorrect user name