I created a service to keep my vpn alive all the time. Whenever the OpenVPN disconnects for any reason the script is restarted by the service. First the script resolves the address provided by my VPN provider to a set of ip addresses and then updates the firewall accordingly. After that it initiates the VPN connection.

When I start my service like this it works fine:

sudo systemctl start alwayson

But it should start automatically at system startup but after startup I get:

● alwayson.service - Always on VPN service
   Loaded: loaded (/etc/systemd/system/alwayson.service; disabled; vendor preset
   Active: inactive (dead)

after running the command:

systemctl status alwayson

Here are the scripts:


Description=Always on VPN service 

ExecStart=/bin/bash /home/user/VPN/alwayson-service/run.sh



echo "Updating FireWall.."

# Remove all rules
list="$(ufw status numbered | awk -F"[][]" '{print $2}' | tac)"
for item in $list
    echo $item
    ufw --force delete $item

# let all incoming traffic pass
ufw default deny incoming
# and block outgoing by default
ufw default deny outgoing
ufw allow out to
ufw allow in from
ufw allow out on tun0
ufw allow out 53

# Allow local IPv4 connections
ufw allow out to
ufw allow out to
ufw allow out to
ufw allow in from

# Allow IPv4 local multicasts
ufw allow out to
ufw allow out to

# Allow local IPv6 connections
ufw allow out to fe80::/64
# Allow IPv6 link-local multicasts
ufw allow out to ff01::/16
# Allow IPv6 site-local multicasts
ufw allow out to ff02::/16
ufw allow out to ff05::/16

# Update Rules for VPN 
list="$(dig +short remote 4-1-gb.cg-dialup.net)"
for item in $list
    echo $item
    ufw allow out to $item
        ufw allow in from $item

# Enable the firewall
ufw enable

openvpn --config /home/doctor/VPN/UK/openvpn.ovpn --script-security 2 --up /home/doctor/VPN/alwayson-service/up.sh --down /home/doctor/VPN/alwayson-service/down.sh --up-restart

Can somebody give me some advice on how to run it at startup?


You need to enable the service in order for it to run at startup. Please run:

sudo systemctl enable alwayson.service

Then it should work automatically after reboot.


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.