The officially official Devuan Forum!

You are not logged in.

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

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

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: 570  

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: 89  

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

#4 2020-12-18 04:23:26

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

Re: Kill openvpn in one line in Terminal

Thanks for this.
I have been using chattr to prevent DNS leakage wink
Seems like you are doing it the proper way. I just found a way to prevent my resolve.conf from changing on me after setting it.

Thanks guys I learned a bit from you smile

pkill will be useful for me.
Also, as I use public Wifi often the 10.100.0.1 DNS is quite common for cisco routers.  It helps me from manually having to change it all the time.
Awesome thank you very much.

Last edited by czeekaj (2020-12-18 04:26:03)

Offline

Board footer