Managing VPNs from the CLI in Linux

Since I have finally made the switch on my work laptop to use Linux (Ubuntu 12.10) as my primary OS, I have found a few bugs that slow me down on a regular basis.  One of the bugs is that the nm-applet will stop working correctly and won’t let me make any changes to the network through the notification icon.  I am able to click the icon to get a drop-down list of networks and configurations, but clicking any item results in not action being taken.  Specifically the part that slows me down the most is the inability to manage VPNs.  When this happens, the VPN submenu is blank and I am obviously unable to connect to any VPNs.  I am able to temporarily fix the issue by either rebooting or restarting the nm-applet:

pkill nm-applet
nm-applet &

 

Unfortunately restarting nm-applet in this way sometimes causes odd behavior within the terminal window that I ran them in and sometimes closing this window causes the nm-applet to disappear altogether. Fortunately the nmcli still works and allows me to manage the network via the command line. I have made a few alias scripts to simplify my most common tasks (add these to ~/.bash_aliases):

alias vpndown='nmcli con down id '
alias vpnlist='nmcli -f name,type con list | grep -i '''name|vpn''''
alias vpnstatus='nmcli -f name,devices,default,vpn con status'
alias vpnup='nmcli con up id '

 

Here are some examples of the aliases in use:

ryan@desktop:~$ vpnlist
NAME TYPE
My VPN1 vpn
My VPN2 vpn
ryan@desktop:~$ vpnup "My VPN1"
ryan@desktop:~$ vpnstatus
NAME DEVICES DEFAULT VPN
My VPN1 eth0 no yes
Wired connection 1 eth0 yes no
ryan@desktop:~$ vpndown "My VPN1"
ryan@desktop:~$

Leave a Reply