4

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 10.8.0.0/24 -o eth0 -j MASQUERADE

But it's not working:

ubuntu@vpn:~$ sudo iptables -t nat -L POSTROUTING
Chain POSTROUTING (policy ACCEPT)
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.

1

2 Answers 2

2

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

#!/bin/sh
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE

Also make sure the file has execution permission:

sudo chmod +x /etc/network/if-up.d/vpn-routing
2
  • this doesn't work for me either. Feb 18, 2014 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, 2016 at 23:18
0

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.

3
  • There's no output in Ubuntu 20.
    – The Onin
    Jan 2, 2021 at 19:19
  • Merely creating that file, of course does absolutely nothing.
    – anon
    Sep 14, 2023 at 13:47
  • Apologies - my response (all those years ago) wasn't very clear :-) I should have added that it was useful for me specifically debugging ppp where the default ppp scripts such as /etc/ppp/ip-up and /etc/ip-down already supported logging based on the existence of the file.
    – higginse
    Sep 15, 2023 at 16:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .