You are not logged in.

#1 2012-12-16 15:23:37

tsr-nc
Member
Registered: 2009-02-07
Posts: 40

Stacking openvpn connections with systemd

I have many openvpn servers,I am trying to stack multiple openvpn connections one though the other, that is I want tun1 to go through tun0. If I enter the commands in order and wait for the interfaces to come up before proceeding, it works. I switch servers, and order of servers, several times a day. I am trying to get this automated. As i can not risk having any data sent over non tunneled channels, I cannot automate much of my system until this is. My problem is that I pull the routing table from the servers that sends my traffic through the tunnel, if i

systemctl start openvpn@(Server1Name)
systemctl start openvpn@(Server2Name)

this will start the Server2 before Server1 is connected and the tun0 interface is up, resulting in 2 interfaces but each connected directly to the Internet.Reading the man systemd.unit i found the "Before= and After=" but i am unsure of how to use these correctly as I switch servers(and ordering) multiple times a day.I have a script that can randomly select the server the next server for me. What i am really hoping for is a way to have systemd only start the next openvpn tunnel after the previous tun[n] interface is up. that is

script picks next random server
start next server
if tun[n] up then n+=1
loop until n = current paranoid level

Why not just put this in a script and run it after startup? Because I need all traffic to go through these tunnels. and not having this at boot means that i cannot have systemd start any network applications(I have a lot). Also but not as important, is it is nice to have the Internet ready to go after boot up.

Offline

#2 2012-12-16 17:30:09

chris_l
Member
Registered: 2010-12-01
Posts: 390

Re: Stacking openvpn connections with systemd

You have your own answer

tsr-nc wrote:

Reading the man systemd.unit i found the "Before= and After="

Yes, that way.
copy the /usr/lib/systemd/system/openvpn@.service to /etc/systemd/system, for each connection you have. and don't forget to name them with different name, like /etc/systemd/system/ovpn1.service, /etc/systemd/system/ovpn2.service, etc

Edit every one of those files, setting both After and Requires putting them in order. and change the %i to be the name of the conf file.

...Not sure why you are doing such thing, I don't think that makes it more secure or anything.


"open source is about choice"
No.
Open source is about opening the source code complying with this conditions, period. The ability to choose among several packages is just a nice side effect.

Offline

Board footer

Powered by FluxBB