Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

# Forward traffic from eth0 through eth1.
-A PREROUTING -i eth1 -p tcp --dport 80 -j DNAT --to
-A PREROUTING -i eth1 -p udp --dport 10090 -j DNAT --to
-A PREROUTING -i eth1 -p tcp --dport 10090 -j DNAT --to
-A PREROUTING -i eth1 -p tcp --dport 443 -j DNAT --to
-A PREROUTING -i eth1 -p udp --dport 443 -j DNAT --to
-A PREROUTING -i eth1 -p tcp --dport 57626 -j DNAT --to
-A PREROUTING -i eth1 -p udp --dport 57626 -j DNAT --to
-A PREROUTING -i eth1 -p tcp --dport 3306 -j DNAT --to
-A PREROUTING -i eth1 -p udp --dport 3306 -j DNAT --to


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

This works for me:

sudo service ufw restart
share|improve this answer
+1 this worked for me – tidwall Feb 12 '14 at 22:39
As I understand it, this is wrong. As in won't even load the new rules. See my question and this bug report (which has been marked as won't fix). Can anyone else confirm this actually working after changing rules in /etc/before.rules? – Nateowami Mar 22 at 10:17
@Nateowami This solution works fine for me. – Matt Borja Jul 7 at 23:35
@MattBorja What version of Ubuntu and ufw? I really don't know much in this area; I've just been going on the bug report which basically said this was intended behavior, and my own experience. – Nateowami Jul 8 at 0:48

It is as simple as it looks:

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


sudo iptables-restore < /etc/before.rules

might work.

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


share|improve this answer

Your Answer


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.