답변:
당신이 실행 ifconfig -a하거나 대부분의 경로 기반 VPN에 사용되는 tun 장치 인 아래와 ip link show같은 것을 보게 되면 tunX:
# 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
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
또는 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)
strongSwan이 정책 기반 라우팅을 실행하는 경우 (기본값) 커널 라우팅 테이블을 조작하거나 ip-xfrm패킷 변환 (페이로드 암호화)을위한 IP 프레임 워크를 확인 하여 파악할 수 있습니다 .
# 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
또한 ip tuntap showVPN을 사용 중인지 확인하기 위해 tun / tap 장치가 있는지 확인할 수 있습니다.
ip tuntap show
tun0: tun
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
주니퍼와 연결 :
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
주니퍼 ncdiag명령을 사용하면이 정보가 제공됩니다.
ncdiag -t터널 테스트에 사용하십시오 .ncdiag -h호스트 정보에 사용 합니다. 더 구체적인 사항 :
$ 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
+ ==================================================== ============================== +
필자의 경우 장치는 cscotun0(Cisco Anyconect Secure Mobility Client를 사용함) tun0입니다.
따라서 (Terry Wang의 답변과 zipizap의 의견을 기반으로) 장치 이름을 모르는 경우 다음을 사용할 수 있습니다.
if [ "0" == `ifconfig | grep tun0 | wc -l` ]; then echo "n"; else echo "y"; fi
또는 장치 이름을 알고있는 경우 :
if ifconfig cscotun0 &>/dev/null; then echo "y"; else echo "n"; fi
UPD Ubuntu 18.04에서는 다음이 필요합니다.
if [ "`ifconfig | grep vpn0`" != "" ] ; then echo yes; else echo no; fi
불행히도, ifconfig vpn0이제 VPN이 작동하지 않더라도 0 (성공)을 반환합니다.
언제 실행되는지 확인
➜ ifconfig -a | grep vpn | grep RUNNING
1:179:vpn0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1334
실행 중이 아닌지 확인
➜ ifconfig -a G vpn
179:vpn0: flags=4240<POINTOPOINT,NOARP,MULTICAST> mtu 1334
아래와 같이 grep을 통해 UP , RUNNING 을 확인할 수 있습니다.
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
내가 사용하고 환상적인 아르고 그놈 쉘 플러그인을, 나는 도구 모음에서 VPN을 시작할 수 있도록 위의 내 스크립트의 일부 (또는 그것을 종료)
ifconfig tun0 &> /dev/null && echo -e "\033[1;32m" "-- VPN is active --" "\033[0m"