I use UFW on my Ubuntu server. Unfortunately there are no rules in UFW to port-forward to another machine.
What you need to do is edit /etc/ufw/before.rules and put routing commands there, for example
# nat Table rules
*nat
:POSTROUTING ACCEPT [0:0]
# Forward traffic from eth0 through eth1.
-A POSTROUTING -s 192.168.0.0/24 -o eth1 -j MASQUERADE
-A PREROUTING -i eth1 -p tcp --dport 80 -j DNAT --to 192.168.0.200:80
-A PREROUTING -i eth1 -p udp --dport 10090 -j DNAT --to 192.168.0.202:22
-A PREROUTING -i eth1 -p tcp --dport 10090 -j DNAT --to 192.168.0.202:22
-A PREROUTING -i eth1 -p tcp --dport 443 -j DNAT --to 192.168.0.200:443
-A PREROUTING -i eth1 -p udp --dport 443 -j DNAT --to 192.168.0.200:443
-A PREROUTING -i eth1 -p tcp --dport 57626 -j DNAT --to 192.168.0.2:57626
-A PREROUTING -i eth1 -p udp --dport 57626 -j DNAT --to 192.168.0.2:57626
-A PREROUTING -i eth1 -p tcp --dport 3306 -j DNAT --to 192.168.0.200:3306
-A PREROUTING -i eth1 -p udp --dport 3306 -j DNAT --to 192.168.0.200:3306
COMMIT
My problem is that I can't find a way to run new forwarding rules without restarting the server, which I hate to do very much.
So please help me, is there a way?
iptables -t nat -L
), but the packets I cared about (ICMP) weren't being masqueraded (but rather being forwarded without NAT, and thus not returned). Here's hoping an answer can be found.