I'm running Ubuntu Server (natty) in as a gateway/firewall in front of a private network. I have successfully enabled IP forwarding and NAT so the machines behind the firewall can connect to Internet (followed the instructions from https://help.ubuntu.com/11.04/serverguide/C/firewall.html).
What I want now, is that a specific IP behind this firewall, whenever wants to connect to an external service to enforced to use only a specific port:
192.168.0.2 (application) -> 184.108.40.2066 (gateway, fictive ip) -> 220.127.116.116 (service, fictive ip)
So whenever 192.168.0.2 wants to connect to 18.104.22.1686 I want it t be enforced by router to use port 10002 (from port range 10002-12000). 22.214.171.1246 allows connections from gateway to ports 10002-12000.
Is there a way to create a custom chain and plug it into ufw, so that I will still be able to use ufw in the intended way and be able to dynamically update this chain whenever I add machines behind this firewall.