Python iptables匹配(uid-owner)错误

时间:2017-07-11 07:00:18

标签: python python-2.7 iptables python-iptables

我正在尝试使用python-iptables库创建以下规则。

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

这是我的代码

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)

我收到以下错误

    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

如何使用此库添加此类规则?

1 个答案:

答案 0 :(得分:0)

问题解决了,问题是用户名不正确