Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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/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?

share|improve this question

4 Answers 4

This works for me:

sudo service ufw restart
share|improve this answer
    
+1 this worked for me –  tidwall Feb 12 at 22:39

It is as simple as it looks:

sudo ufw disable && sudo ufw enable
share|improve this answer

Well

sudo iptables-restore < /etc/before.rules

might work.

share|improve this answer
/etc/init.d/networking restart
/etc/init.d/ufw restart

Source

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.