如何查看我是否通过 VPN 登录?

Mar*_*oma 19 vpn networking

我使用瞻博网络(一个建立 VPN 连接的 Java 程序)。

是否有命令行命令可以让我检查我是否使用 Juniper 登录?

Ter*_*ang 23

如果您运行ifconfig -a或者ip link show您应该看到如下tunX所示的内容,这是大多数基于路由的 VPN 使用的 tun 设备:


# tun device
# used by route-based VPN

    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)

# Jan 2020 refresh
# sample ifconfig output with 3 virtual interfaces
# for route-based VPN or overlay network

nebula1: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST>  mtu 1300
        inet 172.16.87.100  netmask 255.255.255.0  destination 172.16.87.100
        inet6 fe80::b2c4:4360:a3ae:15aa  prefixlen 64  scopeid 0x20<link>
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 500  (UNSPEC)
        RX packets 37  bytes 2980 (2.9 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 331  bytes 17408 (17.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

tun0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST>  mtu 1500
        inet 172.16.200.1  netmask 255.255.255.0  destination 172.16.200.1
        inet6 fe80::9d2e:5979:5ac2:43df  prefixlen 64  scopeid 0x20<link>
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 100  (UNSPEC)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1677  bytes 80496 (80.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wg0: flags=209<UP,POINTOPOINT,RUNNING,NOARP>  mtu 1420
        inet 172.16.111.100  netmask 255.255.255.0  destination 172.16.111.100
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 1000  (UNSPEC)
        RX packets 37337578  bytes 10884991930 (10.8 GB)
        RX errors 0  dropped 67878  overruns 0  frame 0
        TX packets 60202096  bytes 66040772964 (66.0 GB)
        TX errors 169  dropped 44429 overruns 0  carrier 0  collisions 0


Run Code Online (Sandbox Code Playgroud)

ip link 输出


5: wg0: <POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1420 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/none
6: tun0: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN mode DEFAULT group default qlen 100
    link/none
11: nebula1: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1300 qdisc fq_codel state UNKNOWN mode DEFAULT group default qlen 500
    link/none

Run Code Online (Sandbox Code Playgroud)

或者,如果您使用的是 IPsec(例如 strongSwan),ifconfig -a如果您使用的是基于路由的模式(默认是基于策略的),则会显示如下所示的隧道设备 (tunX):

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)
Run Code Online (Sandbox Code Playgroud)

如果 strongSwan 正在运行基于策略的路由(默认),您将能够通过操作内核路由表或查看ip-xfrm用于转换数据包(加密有效负载)的 IP 框架来确定。

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)
Run Code Online (Sandbox Code Playgroud)

此外,您可以使用ip tuntap show查看是否有 tun/tap 设备来确定是否正在使用 VPN。

# manipulate kernel routing table for more info

ip r
route -nr

ip r show table main
ip r show table local

# strongswan specific table id 220
ip r show table 220
Run Code Online (Sandbox Code Playgroud)

  • 基于 Terry Wang 的回答,您可以使用此单行来检查它:`ifconfig tun0 &amp;&gt; /dev/null &amp;&amp; echo -e "\033[1;32m" "-- VPN is active --" "\ 033[0米"` (2认同)

小智 11

您还可以使用该route命令检查您的路线。您会看到更多的正常路线和通往不同目的地的路线。

例子

无杜松连接:

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
Run Code Online (Sandbox Code Playgroud)

与瞻博网络连接:

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
Run Code Online (Sandbox Code Playgroud)