터널 인터페이스에 도착하는 패킷을 어떻게 얻고 사용할 수 있습니까?

터널 인터페이스에 도착하는 패킷을 어떻게 얻고 사용할 수 있습니까?

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 시스템에서 온 것입니다. 10.250.0.0/16 범위의 IP를 ping할 수 있습니다.

관련 정보