[GUIDE] VPN always active



  • Introduction

    Hi, I successfully configured server and client on UT with rpi, pihole and pivpn on it.

    When cellular data connection is poor and it's being interrupted, vpn disconnects and I have to click its switch so many times.

    Problem

    When cellular data connection is poor and it's being interrupted, vpn disconnects and I have to click its switch so many times...

    Question

    What is the nmcli command to enable cellular data connection?

    Solution

    based on this askubuntu thread

    Step 1:
    open terminal on your phone or use ssh as you wish 🙂

    (I replaced UUID with "MY_ID" and my vpn name with "MY_VPN_NAME")

    phablet@ubuntu-phablet:~$ nmcli c show --active | grep vpn
    MY_VPN_NAME             MY_ID  vpn              ril_0  
    

    Step 2:

    phablet@ubuntu-phablet:~$ nmcli c edit MY_ID
    
    ===| nmcli interactive connection editor |===
    
    Editing existing 'vpn' connection: 'MY_ID'
                                                
    Type 'help' or '?' for available commands.  
    Type 'describe [<setting>.<prop>]' for detailed property description.                   
    
    You may edit the following settings: connection, vpn, ipv4, ipv6
    

    Step 3:

    nmcli> print connection.autoconnect
    connection.autoconnect: no
    

    Step 4:

    nmcli> set connection.autoconnect yes
    

    Step 5

    nmcli> save persistent
    Saving the connection with 'autoconnect=yes'. That might result in an immediate activation of the connection.
    Do you still want to save? (yes/no) [yes] yes
    Connection 'MY_VPN_NAME' (MY_ID) successfully updated.
    
    nmcli> 
    
    

    Step 6:
    (based on this askubuntu thread)

    nmcli> print vpn.persistent
    vpn.persistent: no
    

    Step 7:

    nmcli> set vpn.persistent yes
    

    Step 8:

    nmcli> save persistent
    Connection 'MY_VPN_NAME' (MY_ID) successfully updated.
    

    Important
    Save one of needed script in home direction and make it executable, replace only: MY_ID and MY_VPN_NAME
    replace "2s" with any value if you want the script to run at different intervals
    You can also add it to autostart.

    based on this

    To run any of this script you have to use command . /home/phablet/path/to/your/script.sh not sh /home/phablet/path/to/your/script.sh because . is not exactly equal to sh

    Scripts to control always on vpn moved to gitlab:
    https://gitlab.com/big84/UT_uScripts

    On repository this there's wiki which includes important information.

    First Post changelog

    • 2020.11.01 - IMPORTANT! - moved from github to to gitlab.
    • 2020.10.26 - IMPORTANT! - moved scripts with explanation to github
    • 2020.08.20 - added one script, named others, updated all, since today when i edit script 0.0.0 numbers will change
    • 2020.08.19 - changed script which may be the solution if you run it with autostart
    • 2020.08.18 - added "my tests" header, added tag "openvpn"
    • 2020.08.10 - issue creation