当您最初捕获数据包时,您会在默认接口(无论哪个)上看到流量。启用 VPN 时,设置过程的一部分是将 VPN 虚拟接口设置为默认接口。根据您的系统,这意味着在列表中为 VPN 接口提供更高的routing metric 或更高的routing priority。
启用 VPN 连接后,您的路由表应该会发生变化(见下文)。您还应该使用这些命令看到您的 VPN 连接的名称(作为新的默认接口),它可以用作 tcpdump 的接口名称。请注意,根据您的系统/VPN 解决方案,您可能需要进行额外配置以获取必要的 vpn 接口名称。
各种系统上的路由指标
netstat -rn 将显示大多数系统(Windows、Macos、Linux、BSD 等)上的路由表,但不会显示路由指标。
以下命令将向您显示路由指标(显示示例输出)。如您所见,在 Ubuntu/Windows 上,有一个路由度量编号,但在 Macos 上,有一个路由排序。在 Macos 中更改路由顺序的方式实际上是更改列表顺序,例如 networksetup -ordernetworkservices service1, service2...
Ubuntu 18.04
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.0.2.2 0.0.0.0 UG 100 0 0 enp0s3
10.0.2.0 0.0.0.0 255.255.255.0 U 100 0 0 enp0s3
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 enp0s3
Macos 10.15
$ networksetup -listnetworkserviceorder
An asterisk (*) denotes that a network service is disabled.
(1) AX88179 USB 3.0 to Gigabit Ethernet
(Hardware Port: AX88179 USB 3.0 to Gigabit Ethernet, Device: en5)
(2) Wi-Fi
(Hardware Port: Wi-Fi, Device: en0)
(3) Bluetooth PAN
(Hardware Port: Bluetooth PAN, Device: en3)
(4) Thunderbolt Bridge
(Hardware Port: Thunderbolt Bridge, Device: bridge0)
(5) Corporate VPN
(Hardware Port: L2TP, Device: )
Windows 10
C:\Users\rj>route print
===========================================================================
Interface List
5...08 00 27 04 b9 fa ......Intel(R) PRO/1000 MT Desktop Adapter
3...02 00 4c 4f 4f 50 ......Npcap Loopback Adapter
1...........................Software Loopback Interface 1
===========================================================================
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 10.0.2.2 10.0.2.15 25
10.0.2.0 255.255.255.0 On-link 10.0.2.15 281
10.0.2.15 255.255.255.255 On-link 10.0.2.15 281
...