使用N2N软件远程管理DLAP221设备
使用N2N軟件遠程管理DLAP221設備
在大多數的情況下邊緣設備DLAP221一般部署在內網,如果要遠程維護設備,則需要通過公網穿透到內網來登錄設備,這里介紹的N2N軟件正好可以實現這個功能。
N2N分為SuperNode和EdgeNode,前者被稱為超級節點,能夠在EdgeNode之間建立握手并為無法直連的EdgeNode中轉數據,是網絡的核心部分。當然由于SuperNode的重要性,N2N支持為EdgeNode指定多個SuperNode,以便組成更復雜的網絡,并且防止單個SuperNode出問題導致的整個網絡癱瘓。
pc1 <-> center <-> pc2^|v pc3 <-> center <-> pc41. 內核依賴
N2N依賴tun虛擬網卡,默認情況下,DLAP221的Linux內核并沒有開啟tun虛擬網卡模塊,當沒有開啟tun虛擬網卡功能時,在啟動客戶端程序的時候,有如下提示:
ERROR: ioctl() [No such file or directory][2]1.1 編譯tun模塊
修改內核配置文件,將tun虛擬網卡編譯成模塊
-> Device Drivers-> Network device support-> Network core driver support<M> Universal TUN/TAP device driver support在此已經為DLAP221設備編譯好了tun.ko模塊,可以從網盤(提取碼:4npg)下載編譯好的ko文件
1.2 安裝tun模塊
將tun.ko拷貝到DLAP221設備上
$ scp tun.ko HwHiAiUser@192.168.10.2:~ $ cp /home/HwHiAiUser/tun.ko /home/ad_custom/drivers $ sudo vim /var/davinci/scripts/minirc_user_service.sh ...# Miscinsmod ${DRIVERS_DIR}/pl2303.koinsmod ${DRIVERS_DIR}/sd_mod.koinsmod ${DRIVERS_DIR}/sg.koinsmod ${DRIVERS_DIR}/usb-storage.koinsmod ${DRIVERS_DIR}/i2c-mux.koinsmod ${DRIVERS_DIR}/exfat.koinsmod ${DRIVERS_DIR}/cp210x.koinsmod ${DRIVERS_DIR}/tun.ko #在此處添加代碼自動加載tun.ko#dockerinsmod ${DRIVERS_DIR}/br_netfilter.koinsmod ${DRIVERS_DIR}/echainiv.koinsmod ${DRIVERS_DIR}/grace.koinsmod ${DRIVERS_DIR}/iptable_filter.ko ...1.3 檢查tun模塊
$ lsmod|grep tun udp_tunnel 16384 1 vxlan nft_tunnel 16384 0 nf_tables 118784 11 nft_chain_route_ipv4,nft_reject_ipv4,nft_ct,nft_compat,nft_nat,nft_redir,nft_tunnel,nft_dup_ipv4,nft_masq,nft_limit,nft_reject ip_tunnel 28672 0 tun 45056 2 #此處有tun模塊,代表驅動加載成功$ ls /dev/net/tun /dev/net/tun #設備文件成功創建2. 部署
N2N最簡單的部署分為二部分:
-
服務器端部署,也就是超級節點、
-
客戶端部署
注意:edge和super的版本必須一致
2. 服務器端部署
一般部署服務器(超級節點),運行一下命令即可,前提條件是你的客戶端能連接到超級節點
$ supernode -l 7777 #這里端口號可以自行設置,只要不和其他的端口沖突即可由于我們的測試環境沒有公網地址的服務器,所以我們利用官方地址:supernode.ntop.org ,端口號:7777,默認官方的服務器是工作的,所以在此我們不需要做任何事情。
2.2 客戶端部署
為了測試,我們部署跨公網的兩個設備,這兩個設備在各自的內網中,一個是DLAP221設備,另外一臺是pc,相互無法ping通。
另外,考慮到edge和super的版本必須一致,目前我們是用官方的super node,所以我們取最新的代碼進行編譯,而不采用apt install方式安裝n2n軟件。
在兩臺設備上分別下載并編譯n2n:
$ git clone https://github.com/ntop/n2n.git $ cd n2n $ ./autogen.sh $ ./configure $ make# 可選 $ make install在DLAP221上運行以下命令:
$ sudo ./edge -c mynetwork -k mysecretpass -a 192.168.100.1 -f -l supernode.ntop.org:7777 06/Sep/2021 05:47:55 [edge_utils.c:3621] adding supernode = supernode.ntop.org:7777 06/Sep/2021 05:47:55 [edge.c:976] WARNING: switching to AES as key was provided 06/Sep/2021 05:47:55 [edge.c:1016] starting n2n edge 2.9.0 Sep 6 2021 05:46:24 06/Sep/2021 05:47:55 [edge.c:1022] using compression: none. 06/Sep/2021 05:47:55 [edge.c:1023] using AES cipher. 06/Sep/2021 05:47:55 [edge_utils.c:332] number of supernodes in the list: 1 06/Sep/2021 05:47:55 [edge_utils.c:334] supernode 0 => supernode.ntop.org:7777 06/Sep/2021 05:47:55 [edge_utils.c:423] successfully created resolver thread 06/Sep/2021 05:47:55 [edge.c:1047] use manually set IP address 06/Sep/2021 05:47:55 [edge.c:1163] created local tap device IP: 192.168.100.1, Mask: 255.255.255.0, MAC: D6:C4:50:E1:BE:1E 06/Sep/2021 05:47:55 [edge.c:1233] WARNING: n2n has not been compiled with libcap-dev; some commands may fail 06/Sep/2021 05:47:55 [edge.c:1238] dropping privileges to uid=65534, gid=65534 06/Sep/2021 05:47:55 [edge.c:1263] edge started 06/Sep/2021 05:47:55 [edge_utils.c:1054] successfully joined multicast group 224.0.0.68:1968 06/Sep/2021 05:47:55 [edge_utils.c:2614] [OK] edge <<< ================ >>> supernode在遠端PC上運行一下命令:
$ sudo ./edge -c mynetwork -k mysecretpass -a 192.168.100.2 -f -l supernode.ntop.org:7777 [sudo] password for adlink: 06/Sep/2021 13:52:49 [edge_utils.c:3621] adding supernode = supernode.ntop.org:7777 06/Sep/2021 13:52:49 [edge.c:976] WARNING: switching to AES as key was provided 06/Sep/2021 13:52:49 [edge.c:1016] starting n2n edge 2.9.0 Sep 6 2021 13:52:17 06/Sep/2021 13:52:49 [edge.c:1022] using compression: none. 06/Sep/2021 13:52:49 [edge.c:1023] using AES cipher. 06/Sep/2021 13:52:49 [edge_utils.c:332] number of supernodes in the list: 1 06/Sep/2021 13:52:49 [edge_utils.c:334] supernode 0 => supernode.ntop.org:7777 06/Sep/2021 13:52:49 [edge_utils.c:423] successfully created resolver thread 06/Sep/2021 13:52:49 [edge.c:1047] use manually set IP address 06/Sep/2021 13:52:49 [edge.c:1163] created local tap device IP: 192.168.100.2, Mask: 255.255.255.0, MAC: 2A:98:19:2B:32:F8 06/Sep/2021 13:52:49 [edge.c:1233] WARNING: n2n has not been compiled with libcap-dev; some commands may fail 06/Sep/2021 13:52:49 [edge.c:1238] dropping privileges to uid=65534, gid=65534 06/Sep/2021 13:52:49 [edge.c:1263] edge started 06/Sep/2021 13:52:49 [edge_utils.c:1054] successfully joined multicast group 224.0.0.68:1968 06/Sep/2021 13:52:50 [edge_utils.c:2614] [OK] edge <<< ================ >>> supernode參數說明
| -d | 虛擬網卡名 |
| -a | [static: 或者 dhcp:]虛擬網段 (IP),static 模式其實可以不用加那個 static: 直接寫 IP 就行 |
| -c | 用于區分節點的社區 (組) 名 |
| -k | 用于加密的字符串 |
| -K | 用于加密的 Key 文件,和 - k 不能共存 |
| -s | 子網掩碼 |
| -l | supernode 的 IP: 端口,可以指定多個 supernode 的 |
| -i | NAT 打洞間隔 |
| -b | 當使用 DHCP 時定期刷新 IP |
| -p | 指定本地端口 |
| -u | 指定運行所用的 UID |
| -g | 指定運行所用的 GID |
| -f | 前臺運行 |
| -m | 為虛擬網卡指定 MAC 地址 |
| -r | 啟用包轉發,當 - a 指定 DHCP 時需要啟用 |
| -E | 接收組播 MAC 地址 |
| -v | 輸出比較詳細的 log |
| -t | 指定用于管理的 UDP 端口 |
3. 測試
3.1 ping測試
DLAP221 ping PC
$ ping 192.168.100.2 PING 192.168.100.2 (192.168.100.2) 56(84) bytes of data. 64 bytes from 192.168.100.2: icmp_seq=1 ttl=64 time=451 ms 64 bytes from 192.168.100.2: icmp_seq=2 ttl=64 time=453 ms 64 bytes from 192.168.100.2: icmp_seq=3 ttl=64 time=452 ms 64 bytes from 192.168.100.2: icmp_seq=4 ttl=64 time=450 ms 64 bytes from 192.168.100.2: icmp_seq=5 ttl=64 time=450 msPC ping DLAP221
$ ping 192.168.100.1 PING 192.168.100.1 (192.168.100.1) 56(84) bytes of data. 64 bytes from 192.168.100.1: icmp_seq=1 ttl=64 time=436 ms 64 bytes from 192.168.100.1: icmp_seq=2 ttl=64 time=434 ms 64 bytes from 192.168.100.1: icmp_seq=3 ttl=64 time=434 ms 64 bytes from 192.168.100.1: icmp_seq=4 ttl=64 time=435 ms 64 bytes from 192.168.100.1: icmp_seq=5 ttl=64 time=466 ms3.2 ssh登錄測試
從PC端ssh登錄到DLAP221設備:
ssh -l HwHiAiUser 192.168.100.1 The authenticity of host '192.168.100.1 (192.168.100.1)' can't be established. ECDSA key fingerprint is SHA256:p8N+/XArdQdE9MQt1bANLr4vNE+2BFi5Depd+yoV/6c. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.100.1' (ECDSA) to the list of known hosts. HwHiAiUser@192.168.100.1's password: Welcome to Ubuntu 18.04.5 LTS (GNU/Linux 4.19.95+ aarch64)* Documentation: https://help.ubuntu.com* Management: https://landscape.canonical.com* Support: https://ubuntu.com/advantage* Super-optimized for small spaces - read how we shrank the memoryfootprint of MicroK8s to make it the smallest full K8s around.https://ubuntu.com/blog/microk8s-memory-optimisation Last login: Mon Sep 6 04:53:47 2021 from 192.168.31.150 HwHiAiUser@davinci-mini:~$4. 自啟動服務(可選)
配置 DLAP221節點 edge 服務腳本
$ vim /lib/systemd/system/n2n_edge.service [Unit] Description=n2n edge Wants=network-online.target After=network-online.target[Service] ExecStartPre=/bin/sh -c 'until ping -c1 supernode.ntop.org; do sleep 1; done;' ExecStart=/usr/local/n2n/sbin/edge -l supernode.ntop.org:7777 -c n2n0 -a 172.168.3.1 -k 5tgb6yhn7ujm -f[Install] WantedBy=multi-user.target注冊服務并啟動服務
$ systemctl enable n2n_edge Created symlink from /etc/systemd/system/multi-user.target.wants/n2n_edge.service to /lib/systemd/system/n2n_edge.service. $ systemctl start n2n_edge總結
以上是生活随笔為你收集整理的使用N2N软件远程管理DLAP221设备的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Leetcode 2029. 石子游戏
- 下一篇: MSR5560 路由器映射