1

i would like to run the OpenVPN service in the background. I have a script like this, that basically starts the Netherlands VPN of privateinternetaccess.

vpn.sh

sudo openvpn --config /etc/openvpn/privateinternetaccess/Netherlands.ovpn --script-security 2 --up /etc/openvpn/privateinternetaccess/up.sh

The up.sh switches the bind-address-ipv4 value to the current vpn ip address that is obtained.

up.sh

/etc/init.d/transmission-daemon stop sed s/IP_ADDRESS/$4/ /etc/transmission-daemon/settings_template.json > /etc/transmission-daemon/settings.json /etc/init.d/transmission-daemon start

My problem is, i do run this bash script over ssh, and if i exit the ssh the OpenVPN process will stop.

Is there any way to run this in the background? I checked the manual i tried it with an extra --daemon flag, but after that it didn't give any feedback, and i didn't connected to vpn because curl ifconfig.me/ip returns my ip.

closed as off-topic by kolin, Milliways, Bex, lenik, RPiAwesomeness Aug 15 '14 at 15:11

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be specific to the Raspberry Pi within the scope defined in the help center." – kolin, Milliways, Bex, lenik, RPiAwesomeness
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Have you tried something like this on another Linux system (Ubuntu, Debian, Mint, etc.) and had it work? If not, you will get better answers on Unix & Linux as that is a question for Linux-centric issues. Raspberry Pi SE (this site) is for issues that only occur on the Raspberry Pi. – RPiAwesomeness Aug 15 '14 at 15:10
  • Hello, actually my problem got solved already. – tsm Aug 15 '14 at 19:08
2

There is a debian-way of running OpenVPN, which is a lot easier than trying with different scripts on your own.

When you install openvpn using the package manager (apt), like:

sudo apt-get install openvpn

It will create a /etc/openvpn and a /usr/share/doc/openvpn/examples/sample-config-files directories that are relevant to this answer.

Browse the configuration examples in /usr/share/doc/openvpn/examples/sample-config-files and pick one that you can alter to do whatever you want to do with OpenVPN. I assume you will use the client.conf file so that your RPi will connect to some OpenVPN server somewhere.

Copy that file into /etc/openvpn, like this:

sudo cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf /etc/openvpn

Now go to /etc/openvpn and edit the file to your configuration.

Everytime your RPi boots, init will run OpenVPN with all the configuration files in that /etc/openvpn directory, if you don't act otherwise. So, it will automatically start that OpenVPN configuration client.conf that you dropped in there, in the background.

If you want to start/stop it manually, try:

sudo service openvpn stop

or

sudo service openvpn start

accordingly.

Remember that all the configuration files in /etc/openvpn will be executed automatically at boot-time.

  • Thank you, its good to know configs under /etc/ starts after boot. I read through the config file but I have absolutely no idea what should I edit. I am an absolute noob, especially in the networking topic. All i know is i going to use my privateinternetaccess vpn and they have a openvpn.zip package that contains these certificates. – tsm Aug 11 '14 at 8:00

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