The officially official Devuan Forum!

You are not logged in.

#1 2020-08-07 02:00:11

czeekaj
Member
Registered: 2019-06-12
Posts: 49  

Kill openvpn in one line in Terminal

I finally decided to automate something that had been a bit of a time waster for me.

nano /usr/local/sbin/Killvpn

#!/bin/bash

openvpn_pid=$(pidof openvpn | awk '{print $1}')
kill $openvpn_pid

chmod +x /usr/local/sbin/Killvpn


Also you can add local host DNS resolving to the vpn kill script.

echo "search lan
nameserver 192.168.1.1" > /etc/resolv.conf 

Super simple, new to awk but reading a script from GNU user pretty much taught me all I needed to know to get this working. (
found out you wont even need awk for something this simple) Thanks wink

Last edited by czeekaj (2020-08-07 02:05:44)

Offline

#2 2020-08-07 19:01:45

GNUser
Member
Registered: 2017-03-16
Posts: 533  

Re: Kill openvpn in one line in Terminal

Here's how to kill openvpn in one line in terminal:

sudo pkill -f openvpn

Depending on how you run openvpn, you may not need the -f.

Last edited by GNUser (2020-08-07 19:08:41)

Offline

#3 2020-08-11 01:12:12

Vernon
Member
Registered: 2020-07-19
Posts: 82  

Re: Kill openvpn in one line in Terminal

czeekaj wrote:

Also you can add local host DNS resolving to the vpn kill script.

echo "search lan
nameserver 192.168.1.1" > /etc/resolv.conf 

Actually, DNS changing can be better accomplished with the openvpn up and down directives as described here.

Install resolvconf packages using the following command.

apt-get install resolvconf

Add the following lines to each .ovpn file to prevent DNS leakage.

script-security 2
up /etc/openvpn/update-resolv-conf
down /etc/openvpn/update-resolv-conf

The up directive is executed when openvpn starts and forces your Devuan box to use the VPN DNS servers to prevent DNS leakage.

The down directive is executed when you kill openvpn and returns your Devuan box to using the original DNS, in your case 192.168.1.1.

The advantage of using the above method is that if you are mobile and your DNS server IP address changes, the down directive will still correctly return your DNS to the original value. Whereas, your script will incorrectly change the DNS IP address to 192.168.1.1 and you will no longer be able to browse the Internet.

Offline

Board footer