Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have openvpn working fine and it loads at startup as expected. However, without running the following commands on the server I cannot use it to forward the traffic from my client:

sudo iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
su
echo '1' > /proc/sys/net/ipv4/ip_forward

The su is because sudo isn't sufficient (i.e. sudo echo '1' > /proc/sys/net/ipv4/ip_forward will fail so I must use su, log in as root and then run the command. If you know a better way to do this I'm all ears).

I want this to all be done automatically on boot (so after a reboot I don't have to log in via SSH, run the commands and log out again... I want to just launch my client and go) but do not know how to do this. I'm using Ubuntu 10.10 Server.

*FYI this is so I can use this (US based... in my living room) VPN from within China if (when) they block my normal aid VPN (which they do all too frequently).

share|improve this question

1 Answer 1

up vote 1 down vote accepted

You have some options (Actually, you have lots and lots of options, but here are a few):

1) Put those commands into /etc/rc.local (before the "exit 0" line). They will get run on boot.

2) Write an "openvpn-firewall" init script, have it run those commands, and make sure it runs prior to openvpn starting.

3) Use iptables-save and iptables-restore to manage your iptables commands, and put your ip_forward into /etc/sysctl.

a) iptables. Follow the instructions at the Ubuntu IPTables Wiki Page, particularly the "configuration on startup" section.

b) ip_forward. Edit /etc/sysctl.conf and find the line that looks like

#net.ipv4.ip_forward=1

And uncomment it so that it looks like this:

net.ipv4.ip_forward=1

On reboot, this will run automatically.

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.