I use Juniper Networks (a Java program that establishes a VPN connection).

Does a command line command exist that lets me check to see if I'm logged in with Juniper?

up vote 12 down vote accepted

Sounds like some sort of SSL VPN.

If you run ifconfig -a you should be seeing something like tunX below:

tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:  P-t-P:  Mask:
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1300  Metric:1
          RX packets:10 errors:0 dropped:0 overruns:0 frame:0
          TX packets:24 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:500 
          RX bytes:1435 (1.4 KB)  TX bytes:1677 (1.6 KB)

Or if you are using IPsec (e.g. strongSwan based IKEv2 + IPsec), ifconfig -a will show a tunnel device (tunX) like below:

tun0      Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          inet addr:192.168.11.2  P-t-P:192.168.11.2  Mask:255.255.255.255
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:500 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

In addition, you can use ip tuntap show to see if there are tun/tap devices to determine if VPN is in use.

ip tuntap show
tun0: tun
  • 2
    Building upon Terry Wang answer, you can make use this one-liner to check it: ifconfig tun0 &> /dev/null && echo -e "\033[1;32m" "-- VPN is active --" "\033[0m" – zipizap Nov 20 '12 at 11:53

You can also check your routes with the route command. You will see more routes as normal and to different destinations.

Example

Connected without juniper:

moose@pc07:~$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.0.0     *               255.255.255.0   U     2      0        0 wlan0
link-local      *               255.255.0.0     U     1000   0        0 wlan0
default         192.168.0.1     0.0.0.0         UG    0      0        0 wlan0

Connected with Juniper:

moose@pc07:~$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.0.1     *               255.255.255.255 UH    1      0        0 wlan0
vpn.kit.edu     192.168.0.1     255.255.255.255 UGH   1      0        0 wlan0
192.168.0.0     *               255.255.255.0   U     2      0        0 wlan0
link-local      *               255.255.0.0     U     1000   0        0 wlan0
default         vpn-cl-192-62.s 0.0.0.0         UG    1      0        0 tun0
default         192.168.0.1     0.0.0.0         UG    10     0        0 wlan0
  • This is the better answer then the accepted one, at least if you ask me :) – Aleks Dec 17 '14 at 8:29

Using the juniper ncdiag commands will give you this information.

  • Use ncdiag -t for a tunnel test.
  • Use ncdiag -h for host info.

More specifics:

$ cd ~/.juniper_networks/network_connect
~/.juniper_networks/network_connect$ file !$
file ncdiag
ncdiag: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.2.5, stripped
~/.juniper_networks/network_connect$ ./ncdiag 
    usage: ./ncdiag -A [or]
    usage: ./ncdiag -i -s -d -t -h -a -r <hostname> -k -v
     -A : All tests
     -i : installation test 
     -s : service test 
     -d : driver tests 
     -t : tunnel test 
     -h : host info 
     -a : adaptor test 
     -r : resolve host 
     -k : kill NC gui 
     -v : version   

~/.juniper_networks/network_connect$ ./ncdiag -t
+==============================================================================+
|   Tests:          |        Results:                      |
+==============================================================================+
       o  NC Diagnostics            
             NC Tunnel Test          Established

       Finished running tests 
+==============================================================================+
~/.juniper_networks/network_connect$ ./ncdiag -h
+==============================================================================+
|   Tests:          |        Results:                      |
+==============================================================================+

   o  Host Details              
         Hostname            tau
         Domainname          (none)
         IP Routing Enabled      Yes
         IP Loopback test        Passed
         Nameserver Details     
           8.8.8.8       Ping Passed

           8.8.6.6       Ping Passed
         Gateway Ping Test           
            10.20.20.1       Ping Passed

   Finished running tests 

+==============================================================================+

In my case, the device is cscotun0 (I use Cisco Anyconect Secure Mobility Client) rather than tun0.

Therefore (based on Terry Wang's answer and zipizap's comment), if you do not know the device name, you may use:

if [ "0" == `ifconfig | grep tun0 | wc -l` ]; then echo "n"; else echo "y"; fi

or, if you know the device name:

if ifconfig cscotun0 &>/dev/null; then echo "y"; else echo "n"; fi

Alternative solution (Gnome)


Check when it's running

➜ ifconfig -a | grep vpn | grep RUNNING
1:179:vpn0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST>  mtu 1334

Check when it's not running

➜ ifconfig -a G vpn
179:vpn0: flags=4240<POINTOPOINT,NOARP,MULTICAST>  mtu 1334

so you can check for UP, RUNNING via grep as shown below

ifconfig -a | grep vpn | grep RUNNING
vpn_running=$?

if [ $vpn_running -ne 0 ]; then

    echo "VPN <span color='yellow'><tt>UP</tt></span> | iconName=utilities-terminal-symbolic bash='nmcli con up id VPN' terminal=false"
else
    echo "VPN <span color='red'><tt>(DOWN)</tt></span> | iconName=utilities-terminal-symbolic bash='nmcli con down id VPN' terminal=false"
fi

I'm using fantastic argo gnome shell plugin, and above is part of my script so I can launch VPN from toolbar (or shut it down)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.