iptables module with port forwarding

84 views
Skip to first unread message

Chun-Hung Huang

unread,
Jul 21, 2016, 2:41:54 AM7/21/16
to Ansible Project
Hi ALL

I want to use iptables module to manage port forwarding

---->  EXT_IP:EXT_PORT  ---->   INT_IP:INT:PORT

If user request  EXT_IP with port 8001, it will forward to INT_IP ( 192.168.100.131 ) and port 22. 

I use iptables module but fail

# ansible   -m iptables   -a 'table=nat   chain=PREROUTING   protocol=tcp   match=tcp   destination_port=8001   jump=REDIRECT to_destination=192.168.100.131   to_ports=22'   gateway   --ask-pass


gateway | FAILED! => {

    "changed": false, 

    "cmd": "/usr/sbin/iptables -t nat -A PREROUTING -p tcp -m tcp -j REDIRECT --to-destination 192.168.100.131 --destination-port 8001 --to-ports 22", 

    "failed": true, 

    "msg": "iptables v1.4.21: unknown option \"--to-destination\"\nTry `iptables -h' or 'iptables --help' for more information.", 

    "rc": 2, 

    "stderr": "iptables v1.4.21: unknown option \"--to-destination\"\nTry `iptables -h' or 'iptables --help' for more information.\n", 

    "stdout": "", 

    "stdout_lines": []

}


I already check https://docs.ansible.com/ansible/iptables_module.html


Pleas tell me which option I should use?



Thanks


Reply all
Reply to author
Forward
0 new messages