I'm trying to make NAT routing persistent on my Ubuntu 12.04 EC2 instance (for OpenVPN; currently I need to run it every time after boot):

ubuntu@vpn:~$ cat /etc/network/if-up.d/vpn-routing
iptables -t nat -A POSTROUTING -s -o eth0 -j MASQUERADE

But it's not working:

ubuntu@vpn:~$ sudo iptables -t nat -L POSTROUTING
target     prot opt source               destination

Any ideas why? Does it matter that I have ufw enabled? I didn't see anything interesting/relevant in syslog (though I wasn't sure what to look for). Thanks in advance.


I think it's because the file doesn't have a shebang line. It should be something like:

iptables -t nat -A POSTROUTING -s -o eth0 -j MASQUERADE

Also make sure the file has execution permission:

sudo chmod +x /etc/network/if-up.d/vpn-routing
  • this doesn't work for me either. – Joshua Robison Feb 18 '14 at 0:46
  • Actually the #!/bin/sh fixed it for me. Though there could be any number of reasons it's not working – Nuzzolilo Jan 3 '16 at 23:18

I've had trouble with this myself. One handy way of debugging is to enable the logfile for ppp... sudo touch /var/log/ppp-ipupdown.log

then when I bring up a ppp session I can see how my script is behaving.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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