Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rules added via iptc - not found in iptables o/p #320

Closed
renukamanavalan opened this issue Apr 27, 2021 · 5 comments
Closed

Rules added via iptc - not found in iptables o/p #320

renukamanavalan opened this issue Apr 27, 2021 · 5 comments

Comments

@renukamanavalan
Copy link

  1. Created a rule via iptc.easy.insert_rule
  2. Could see it in iptc.easy.dump_table
  3. Did table.commit()
  4. exit the python interpreter
  5. Look in "sudo iptables -t nat -L" and unable to find this entry.

Any tips on, what I am missing please?

admin@str-s6000-acs-9:~/files$ sudo python3           
Python 3.7.3 (default, Jan 22 2021, 20:04:44) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import iptc
>>> table = iptc.Table("nat")
>>> chain = iptc.Chain(table, "OUTPUT")
>>> rule = {"dst": "172.16.1.1", "protocol": "tcp", "tcp": {"dport": 3128}, "target": {"DNAT": {"to-destination": "100.127.20.21:8080" }}}
>>> iptc.easy.insert_rule("nat", "OUTPUT", rule)
>>> iptc.easy.dump_table('nat', ipv6=False)
{'PREROUTING': [], 'INPUT': [], 'OUTPUT': [{'dst': '172.16.1.1/32', 'protocol': 'tcp', 'tcp': {}, 'target': {'DNAT': {'to-destination': '100.127.20.21:8080'}}, 'counters': (0, 0)}, {'dst': '172.16.1.1/32', 'protocol': 'tcp', 'tcp': {}, 'target': {'DNAT': {'to-destination': '100.127.20.21:8080'}}, 'counters': (0, 0)}], 'POSTROUTING': []}
>>> table.commit()
>>> quit()
admin@str-s6000-acs-9:~/files$ sudo iptables -t nat -L | grep 8080
# Warning: iptables-legacy tables present, use iptables-legacy to see them
admin@str-s6000-acs-9:~/files$ sudo iptables -t nat -L 
Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination         

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
KUBE-POSTROUTING  all  --  anywhere             anywhere             /* kubernetes postrouting rules */

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain KUBE-MARK-DROP (0 references)
target     prot opt source               destination         
MARK       all  --  anywhere             anywhere             MARK or 0x8000

Chain KUBE-MARK-MASQ (0 references)
target     prot opt source               destination         
MARK       all  --  anywhere             anywhere             MARK or 0x4000

Chain KUBE-POSTROUTING (1 references)
target     prot opt source               destination         
RETURN     all  --  anywhere             anywhere             mark match ! 0x4000/0x4000
MARK       all  --  anywhere             anywhere             MARK xor 0x4000
MASQUERADE  all  --  anywhere             anywhere             /* kubernetes service traffic requiring SNAT */ random-fully

Chain KUBE-KUBELET-CANARY (0 references)
target     prot opt source               destination         
# Warning: iptables-legacy tables present, use iptables-legacy to see them
admin@str-s6000-acs-9:~/files$ 

@renukamanavalan
Copy link
Author

print(table.autocommit)
True

Just verified. Auto-commit is indeed true.

@jllorente
Copy link
Collaborator

If your iptables package has been compiled with "nf_tables" support, then you need to use "iptables-legacy" command instead.

$ sudo iptables -V
iptables v1.8.2 (nf_tables)
$ sudo iptables-legacy -t nat -L

Please try again and let me know

@renukamanavalan
Copy link
Author

renukamanavalan commented Apr 27, 2021

Thanks a lot. It did work.

Is there a plan to upgrade this package to use nf_tables ?

As other components are using the nf_tables (new/current default), my component need to be in sync.

@ldx
Copy link
Owner

ldx commented Apr 27, 2021

A related thread and comment here: #306 (comment)

@renukamanavalan
Copy link
Author

Thank you, Vilmos!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants