paint-brush
Running openvpn as a systemd service.by@mikefettis
1,747 reads
1,747 reads

Running openvpn as a systemd service.

by mike fettisJanuary 12th, 2019
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

VPNs are all the rage. All the cool kids are using them. The coolest kids only use a terminal on their linux. How about running openvpn as a systemd service and have an interactive prompt to let you know that your vpn is running?

Company Mentioned

Mention Thumbnail
featured image - Running openvpn as a systemd service.
mike fettis HackerNoon profile picture

photo by: mike fettis

VPNs are all the rage. All the cool kids are using them. The coolest kids only use a terminal on their linux. How about running openvpn as a systemd service and have an interactive prompt to let you know that your vpn is running?




Enter systemd, and PS1.The trick is to run the openvpn command as a systemd service. Then set it to auto-restart 15 seconds after failure. If we add a line to the opvn config file, auth-user-pass /home/linuxuser/pass.txt and then have the openvpn username and password in said txt file openvpn will be able to automatically connect to the vpn host. Finally, the icing on the cake is to update my PS1 (terminal prompt) to change color if the vpn is connected. This can be accomplished two different ways. 1). If the traceroute resolves the first hop to a 10.* ip address then I know that my vpn is connected2). If the service is in an active state then I know its running.

The in depth process is below.

There you have it, the vpn service will start on boot and will remain running all the time. If there is an issue then it will autorestart after 15 seconds. Just as a safeguard to make sure that all is good because we always want to know if the vpn is running ;) our terminal prompt will change colors based on the situation. A further enhancement can be done if you don’t want the entire terminal to change color and just hav ea symbol. This can be done if you look at the git integration that was done by, magicmonty. Hope this was a quick and easy read, and good luck with all your VPN-ing!


magicmonty/bash-git-prompt_An informative and fancy bash prompt for Git users - magicmonty/bash-git-prompt_github.com

links!!


systemd.service_It is possible for systemd services to take a single argument via the "" syntax. Such services are called…_www.freedesktop.org


BASH Shell Change The Color of Shell Prompt on Linux or UNIX - nixCraft_How do I change the color of my shell prompt under Linux or Unix operating systems? You can change the color of your…_www.cyberciti.biz


My new favorite Bash prompt - BrettTerpstra.com_I do a lot in Terminal. Sometimes, it's easier. Sometimes it's faster. Sometimes I'd just rather type it out. Whatever…_brettterpstra.com