我在 Linux 中创建了一个隧道接口,并为其本地和远程地址分配了一个 IP。然后,我为该接口创建了一条路由。我想让数据包到达该接口并在其他地方使用它们。例如,使用 TCP/UDP 套接字将数据包发送到某个主机。我尝试这样做是出于研究目的和学习目的。我可能做的完全不相关,请纠正我。
这是我运行过的命令。
sudo ip tunnel add mytun mode ipip local 10.2.1.1 remote 10.2.1.1
sudo ip link set mytun up
sudo ip route add 10.2.0.0/16 dev mytun
我想发送一个数据包到10.2.1.2
隧道接口并捕获该数据包。
显然,我在概念上遗漏了一些东西,并且可能混淆了一些东西。我听说一些 VPN 客户端实现了类似的功能,创建隧道接口并将该接口中的流量通过 UDP 通道路由到 VPN 网关。我想探索事物是如何运作的并进行实验。
编辑:
这是按照我所描述的方式工作的计算机的输出。计算机已连接到 VPN 客户端。
% ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP>
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
nd6 options=201<PERFORMNUD,DAD>
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en5: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether ac:de:48:00:11:22
inet6 fe80::aede:48ff:fe00:1122%en5 prefixlen 64 scopeid 0x4
nd6 options=201<PERFORMNUD,DAD>
media: autoselect (100baseTX <full-duplex>)
status: active
ap1: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500
options=400<CHANNEL_IO>
ether aa:66:5a:01:9c:72
media: autoselect
status: inactive
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=400<CHANNEL_IO>
ether 88:66:5a:01:9c:72
inet6 fe80::4e3:d805:211e:482c%en0 prefixlen 64 secured scopeid 0x6
inet 192.168.1.27 netmask 0xffffff00 broadcast 192.168.1.255
nd6 options=201<PERFORMNUD,DAD>
media: autoselect
status: active
p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304
options=400<CHANNEL_IO>
ether 0a:66:5a:01:9c:72
media: autoselect
status: inactive
awdl0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1484
options=400<CHANNEL_IO>
ether d2:41:09:96:68:02
inet6 fe80::d041:9ff:fe96:6802%awdl0 prefixlen 64 scopeid 0x8
nd6 options=201<PERFORMNUD,DAD>
media: autoselect
status: active
llw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=400<CHANNEL_IO>
ether d2:41:09:96:68:02
inet6 fe80::d041:9ff:fe96:6802%llw0 prefixlen 64 scopeid 0x9
nd6 options=201<PERFORMNUD,DAD>
media: autoselect
status: active
en1: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
options=460<TSO4,TSO6,CHANNEL_IO>
ether 82:bc:33:c0:a0:01
media: autoselect <full-duplex>
status: inactive
en2: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
options=460<TSO4,TSO6,CHANNEL_IO>
ether 82:bc:33:c0:a0:00
media: autoselect <full-duplex>
status: inactive
en3: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
options=460<TSO4,TSO6,CHANNEL_IO>
ether 82:bc:33:c0:a0:05
media: autoselect <full-duplex>
status: inactive
en4: flags=8963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
options=460<TSO4,TSO6,CHANNEL_IO>
ether 82:bc:33:c0:a0:04
media: autoselect <full-duplex>
status: inactive
bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=63<RXCSUM,TXCSUM,TSO4,TSO6>
ether 82:bc:33:c0:a0:01
Configuration:
id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0
maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200
root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0
ipfilter disabled flags 0x0
member: en1 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 10 priority 0 path cost 0
member: en2 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 11 priority 0 path cost 0
member: en3 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 12 priority 0 path cost 0
member: en4 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 13 priority 0 path cost 0
nd6 options=201<PERFORMNUD,DAD>
media: <unknown type>
status: inactive
utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1380
inet6 fe80::8a35:50aa:7ece:babb%utun0 prefixlen 64 scopeid 0xf
nd6 options=201<PERFORMNUD,DAD>
utun1: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 2000
inet6 fe80::1fca:c7f5:9c76:6e18%utun1 prefixlen 64 scopeid 0x10
nd6 options=201<PERFORMNUD,DAD>
utun2: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1400
inet 10.212.232.54 --> 10.212.232.54 netmask 0xffffffff
% netstat -r -n
Routing tables
Internet:
Destination Gateway Flags Netif Expire
default 192.168.1.1 UGSc en0
10/24 10.212.232.54 UGSc utun2
10.0.1/24 10.212.232.54 UGSc utun2
10.0.2/24 10.212.232.54 UGSc utun2
10.0.3/24 10.212.232.54 UGSc utun2
10.0.4/24 10.212.232.54 UGSc utun2
10.0.5/24 10.212.232.54 UGSc utun2
10.0.6/24 10.212.232.54 UGSc utun2
10.0.10/24 10.212.232.54 UGSc utun2
10.0.20/24 10.212.232.54 UGSc utun2
10.0.30/24 10.212.232.54 UGSc utun2
10.0.31/24 10.212.232.54 UGSc utun2
10.0.33/24 10.212.232.54 UGSc utun2
10.0.50/24 10.212.232.54 UGSc utun2
10.0.70/24 10.212.232.54 UGSc utun2
10.0.80/23 10.212.232.54 UGSc utun2
10.0.100/24 10.212.232.54 UGSc utun2
10.1.10/24 10.212.232.54 UGSc utun2
10.1.20/24 10.212.232.54 UGSc utun2
10.1.50/24 10.212.232.54 UGSc utun2
10.1.200/24 10.212.232.54 UGSc utun2
10.2.10/24 10.212.232.54 UGSc utun2
10.2.20/24 10.212.232.54 UGSc utun2
10.2.50/24 10.212.232.54 UGSc utun2
10.2.80/24 10.212.232.54 UGSc utun2
10.2.81/24 10.212.232.54 UGSc utun2
10.10/16 10.212.232.54 UGSc utun2
10.10.10/24 10.212.232.54 UGSc utun2
10.10.20/24 10.212.232.54 UGSc utun2
10.10.30/24 10.212.232.54 UGSc utun2
10.10.35/29 10.212.232.54 UGSc utun2
10.10.36/22 10.212.232.54 UGSc utun2
10.10.40/24 10.212.232.54 UGSc utun2
10.10.41/24 10.212.232.54 UGSc utun2
10.10.42/23 10.212.232.54 UGSc utun2
10.10.42.7 10.212.232.54 UGHS utun2
10.10.42.8 10.212.232.54 UGHS utun2
10.10.44/24 10.212.232.54 UGSc utun2
10.10.45/24 10.212.232.54 UGSc utun2
10.10.46/24 10.212.232.54 UGSc utun2
10.10.47/24 10.212.232.54 UGSc utun2
10.10.48/21 10.212.232.54 UGSc utun2
10.10.56/22 10.212.232.54 UGSc utun2
10.10.60/24 10.212.232.54 UGSc utun2
10.10.61/24 10.212.232.54 UGSc utun2
10.10.62/24 10.212.232.54 UGSc utun2
10.10.65/24 10.212.232.54 UGSc utun2
10.10.70/24 10.212.232.54 UGSc utun2
10.10.80/24 10.212.232.54 UGSc utun2
10.10.81/24 10.212.232.54 UGSc utun2
10.10.82/24 10.212.232.54 UGSc utun2
10.10.87/24 10.212.232.54 UGSc utun2
10.10.90/24 10.212.232.54 UGSc utun2
10.10.93/24 10.212.232.54 UGSc utun2
10.10.95/24 10.212.232.54 UGSc utun2
10.10.112/24 10.212.232.54 UGSc utun2
10.10.120/24 10.212.232.54 UGSc utun2
10.10.150/24 10.212.232.54 UGSc utun2
10.10.151/24 10.212.232.54 UGSc utun2
10.10.180/24 10.212.232.54 UGSc utun2
10.10.182/24 10.212.232.54 UGSc utun2
10.10.184/22 10.212.232.54 UGSc utun2
10.10.200/21 10.212.232.54 UGSc utun2
10.10.212/24 10.212.232.54 UGSc utun2
10.10.220/24 10.212.232.54 UGSc utun2
10.20/16 10.212.232.54 UGSc utun2
10.20.40.128/25 10.212.232.54 UGSc utun2
10.30.30/24 10.212.232.54 UGSc utun2
10.32/24 10.212.232.54 UGSc utun2
10.32.1/24 10.212.232.54 UGSc utun2
10.32.2/24 10.212.232.54 UGSc utun2
10.32.3/24 10.212.232.54 UGSc utun2
10.32.4/24 10.212.232.54 UGSc utun2
10.32.5/24 10.212.232.54 UGSc utun2
10.32.6/24 10.212.232.54 UGSc utun2
10.32.16/24 10.212.232.54 UGSc utun2
10.32.16.252/30 10.212.232.54 UGSc utun2
10.32.34/24 10.212.232.54 UGSc utun2
10.32.36/24 10.212.232.54 UGSc utun2
10.32.199/24 10.212.232.54 UGSc utun2
10.32.249/24 10.212.232.54 UGSc utun2
10.32.250/24 10.212.232.54 UGSc utun2
10.32.251/24 10.212.232.54 UGSc utun2
10.32.252/24 10.212.232.54 UGSc utun2
10.32.253/24 10.212.232.54 UGSc utun2
10.32.254/24 10.212.232.54 UGSc utun2
10.34/24 10.212.232.54 UGSc utun2
10.34.1/24 10.212.232.54 UGSc utun2
10.34.21/24 10.212.232.54 UGSc utun2
10.36/24 10.212.232.54 UGSc utun2
10.36.1/24 10.212.232.54 UGSc utun2
10.40/16 10.212.232.54 UGSc utun2
10.41/16 10.212.232.54 UGSc utun2
10.43/16 10.212.232.54 UGSc utun2
10.45/16 10.212.232.54 UGSc utun2
10.46/16 10.212.232.54 UGSc utun2
10.47/16 10.212.232.54 UGSc utun2
10.49/16 10.212.232.54 UGSc utun2
10.51/24 10.212.232.54 UGSc utun2
10.51.1/24 10.212.232.54 UGSc utun2
10.52/16 10.212.232.54 UGSc utun2
10.53/16 10.212.232.54 UGSc utun2
10.54/15 10.212.232.54 UGSc utun2
10.56/15 10.212.232.54 UGSc utun2
10.58/16 10.212.232.54 UGSc utun2
10.59/16 10.212.232.54 UGSc utun2
10.60/16 10.212.232.54 UGSc utun2
10.61/16 10.212.232.54 UGSc utun2
10.66/24 10.212.232.54 UGSc utun2
10.66.1/24 10.212.232.54 UGSc utun2
10.66.2/24 10.212.232.54 UGSc utun2
10.66.3/24 10.212.232.54 UGSc utun2
10.66.12/22 10.212.232.54 UGSc utun2
10.75/23 10.212.232.54 UGSc utun2
10.100/22 10.212.232.54 UGSc utun2
10.100.4/22 10.212.232.54 UGSc utun2
10.100.7/24 10.212.232.54 UGSc utun2
10.100.8/24 10.212.232.54 UGSc utun2
10.100.11/24 10.212.232.54 UGSc utun2
10.100.12/24 10.212.232.54 UGSc utun2
10.101.64/18 10.212.232.54 UGSc utun2
10.104.100/23 10.212.232.54 UGSc utun2
10.110/16 10.212.232.54 UGSc utun2
10.123/16 10.212.232.54 UGSc utun2
10.130/16 10.212.232.54 UGSc utun2
10.130.200/24 10.212.232.54 UGSc utun2
10.140/16 10.212.232.54 UGSc utun2
10.145/16 10.212.232.54 UGSc utun2
10.146.8/22 10.212.232.54 UGSc utun2
10.146.24/24 10.212.232.54 UGSc utun2
10.146.25/26 10.212.232.54 UGSc utun2
10.146.26/27 10.212.232.54 UGSc utun2
10.146.28/22 10.212.232.54 UGSc utun2
10.146.32/22 10.212.232.54 UGSc utun2
10.146.254/24 10.212.232.54 UGSc utun2
10.147/21 10.212.232.54 UGSc utun2
10.147.16/21 10.212.232.54 UGSc utun2
10.147.32/21 10.212.232.54 UGSc utun2
10.147.48/21 10.212.232.54 UGSc utun2
10.147.64/21 10.212.232.54 UGSc utun2
10.147.80/21 10.212.232.54 UGSc utun2
10.147.96/21 10.212.232.54 UGSc utun2
10.147.112/21 10.212.232.54 UGSc utun2
10.147.128/21 10.212.232.54 UGSc utun2
10.147.144/21 10.212.232.54 UGSc utun2
10.147.160/21 10.212.232.54 UGSc utun2
10.147.176/21 10.212.232.54 UGSc utun2
10.147.192/21 10.212.232.54 UGSc utun2
10.147.200/21 10.212.232.54 UGSc utun2
10.147.208/21 10.212.232.54 UGSc utun2
10.147.216/21 10.212.232.54 UGSc utun2
10.147.224/21 10.212.232.54 UGSc utun2
10.147.232/21 10.212.232.54 UGSc utun2
10.147.240/21 10.212.232.54 UGSc utun2
10.147.248/21 10.212.232.54 UGSc utun2
10.178.229.31 10.212.232.54 UGHS utun2
10.201/16 10.212.232.54 UGSc utun2
10.202/16 10.212.232.54 UGSc utun2
10.203/16 10.212.232.54 UGSc utun2
10.204/16 10.212.232.54 UGSc utun2
10.212.232.54/32 127.0.0.1 UGSc lo0
10.226/16 10.212.232.54 UGSc utun2
10.250/21 10.212.232.54 UGSc utun2
10.250/16 10.212.232.54 UGSc utun2
10.250.8/21 10.212.232.54 UGSc utun2
10.250.16/21 10.212.232.54 UGSc utun2
10.250.24/21 10.212.232.54 UGSc utun2
10.250.32/21 10.212.232.54 UGSc utun2
10.250.40/21 10.212.232.54 UGSc utun2
10.250.48/21 10.212.232.54 UGSc utun2
10.250.56/21 10.212.232.54 UGSc utun2
10.250.64/21 10.212.232.54 UGSc utun2
10.250.72/21 10.212.232.54 UGSc utun2
10.250.80/24 10.212.232.54 UGSc utun2
10.250.88/21 10.212.232.54 UGSc utun2
10.250.96/21 10.212.232.54 UGSc utun2
10.250.104/21 10.212.232.54 UGSc utun2
10.250.112/21 10.212.232.54 UGSc utun2
10.250.120/24 10.212.232.54 UGSc utun2
10.250.122/25 10.212.232.54 UGSc utun2
10.250.122.128/27 10.212.232.54 UGSc utun2
10.250.124/24 10.212.232.54 UGSc utun2
10.250.125/24 10.212.232.54 UGSc utun2
10.250.126/24 10.212.232.54 UGSc utun2
10.250.127/24 10.212.232.54 UGSc utun2
10.250.128/24 10.212.232.54 UGSc utun2
10.250.129/24 10.212.232.54 UGSc utun2
10.250.130/24 10.212.232.54 UGSc utun2
10.250.131/24 10.212.232.54 UGSc utun2
10.250.132/24 10.212.232.54 UGSc utun2
10.250.133/24 10.212.232.54 UGSc utun2
10.250.134/24 10.212.232.54 UGSc utun2
10.250.136/24 10.212.232.54 UGSc utun2
10.250.137/24 10.212.232.54 UGSc utun2
10.250.138/24 10.212.232.54 UGSc utun2
10.250.139/24 10.212.232.54 UGSc utun2
10.250.146/24 10.212.232.54 UGSc utun2
10.250.147/24 10.212.232.54 UGSc utun2
10.250.148/24 10.212.232.54 UGSc utun2
10.250.149/24 10.212.232.54 UGSc utun2
10.250.150/24 10.212.232.54 UGSc utun2
10.250.200/21 10.212.232.54 UGSc utun2
10.250.208/21 10.212.232.54 UGSc utun2
10.250.216/21 10.212.232.54 UGSc utun2
127 127.0.0.1 UCS lo0
127.0.0.1 127.0.0.1 UH lo0
169.254 link#6 UCS en0 !
172.16.20/24 10.212.232.54 UGSc utun2
172.16.22/24 10.212.232.54 UGSc utun2
172.16.30/24 10.212.232.54 UGSc utun2
172.16.40/22 10.212.232.54 UGSc utun2
172.16.44/24 10.212.232.54 UGSc utun2
172.16.135/24 10.212.232.54 UGSc utun2
172.16.136/24 10.212.232.54 UGSc utun2
172.16.137/24 10.212.232.54 UGSc utun2
172.16.138/24 10.212.232.54 UGSc utun2
172.16.139/24 10.212.232.54 UGSc utun2
172.16.140/24 10.212.232.54 UGSc utun2
172.17/21 10.212.232.54 UGSc utun2
172.18 10.212.232.54 UGSc utun2
192.168.0/16 10.212.232.54 UGSc utun2
192.168.1 link#6 UCS en0 !
192.168.1.1 50:68:a:63:26:e8 UHLS en0
192.168.1.1/32 link#6 UCS en0 !
192.168.1.1 50:68:a:63:26:e8 UHLWIir en0 1194
192.168.1.27/32 link#6 UCS en0 !
192.168.2 10.212.232.54 UGSc utun2
224.0.0/4 link#6 UmCS en0 !
224.0.0.251 1:0:5e:0:0:fb UHmLWI en0
239.255.255.250 1:0:5e:7f:ff:fa UHmLWI en0
255.255.255.255/32 link#6 UCS en0 !
请注意,公共 IP 已被编辑,并且来自 macOS 系统。我可以 ping 通 10.250.0.0/16 范围内的 IP。