使用N2N软件远程管理DLAP221设备
使用N2N軟件遠(yuǎn)程管理DLAP221設(shè)備
在大多數(shù)的情況下邊緣設(shè)備DLAP221一般部署在內(nèi)網(wǎng),如果要遠(yuǎn)程維護(hù)設(shè)備,則需要通過公網(wǎng)穿透到內(nèi)網(wǎng)來登錄設(shè)備,這里介紹的N2N軟件正好可以實(shí)現(xiàn)這個(gè)功能。
N2N分為SuperNode和EdgeNode,前者被稱為超級(jí)節(jié)點(diǎn),能夠在EdgeNode之間建立握手并為無法直連的EdgeNode中轉(zhuǎn)數(shù)據(jù),是網(wǎng)絡(luò)的核心部分。當(dāng)然由于SuperNode的重要性,N2N支持為EdgeNode指定多個(gè)SuperNode,以便組成更復(fù)雜的網(wǎng)絡(luò),并且防止單個(gè)SuperNode出問題導(dǎo)致的整個(gè)網(wǎng)絡(luò)癱瘓。
pc1 <-> center <-> pc2^|v pc3 <-> center <-> pc41. 內(nèi)核依賴
N2N依賴tun虛擬網(wǎng)卡,默認(rèn)情況下,DLAP221的Linux內(nèi)核并沒有開啟tun虛擬網(wǎng)卡模塊,當(dāng)沒有開啟tun虛擬網(wǎng)卡功能時(shí),在啟動(dòng)客戶端程序的時(shí)候,有如下提示:
ERROR: ioctl() [No such file or directory][2]1.1 編譯tun模塊
修改內(nèi)核配置文件,將tun虛擬網(wǎng)卡編譯成模塊
-> Device Drivers-> Network device support-> Network core driver support<M> Universal TUN/TAP device driver support在此已經(jīng)為DLAP221設(shè)備編譯好了tun.ko模塊,可以從網(wǎng)盤(提取碼:4npg)下載編譯好的ko文件
1.2 安裝tun模塊
將tun.ko拷貝到DLAP221設(shè)備上
$ 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 #在此處添加代碼自動(dòng)加載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模塊,代表驅(qū)動(dòng)加載成功$ ls /dev/net/tun /dev/net/tun #設(shè)備文件成功創(chuàng)建2. 部署
N2N最簡單的部署分為二部分:
-
服務(wù)器端部署,也就是超級(jí)節(jié)點(diǎn)、
-
客戶端部署
注意:edge和super的版本必須一致
2. 服務(wù)器端部署
一般部署服務(wù)器(超級(jí)節(jié)點(diǎn)),運(yùn)行一下命令即可,前提條件是你的客戶端能連接到超級(jí)節(jié)點(diǎn)
$ supernode -l 7777 #這里端口號(hào)可以自行設(shè)置,只要不和其他的端口沖突即可由于我們的測(cè)試環(huán)境沒有公網(wǎng)地址的服務(wù)器,所以我們利用官方地址:supernode.ntop.org ,端口號(hào):7777,默認(rèn)官方的服務(wù)器是工作的,所以在此我們不需要做任何事情。
2.2 客戶端部署
為了測(cè)試,我們部署跨公網(wǎng)的兩個(gè)設(shè)備,這兩個(gè)設(shè)備在各自的內(nèi)網(wǎng)中,一個(gè)是DLAP221設(shè)備,另外一臺(tái)是pc,相互無法ping通。
另外,考慮到edge和super的版本必須一致,目前我們是用官方的super node,所以我們?nèi)∽钚碌拇a進(jìn)行編譯,而不采用apt install方式安裝n2n軟件。
在兩臺(tái)設(shè)備上分別下載并編譯n2n:
$ git clone https://github.com/ntop/n2n.git $ cd n2n $ ./autogen.sh $ ./configure $ make# 可選 $ make install在DLAP221上運(yùn)行以下命令:
$ 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在遠(yuǎn)端PC上運(yùn)行一下命令:
$ 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參數(shù)說明
| -d | 虛擬網(wǎng)卡名 |
| -a | [static: 或者 dhcp:]虛擬網(wǎng)段 (IP),static 模式其實(shí)可以不用加那個(gè) static: 直接寫 IP 就行 |
| -c | 用于區(qū)分節(jié)點(diǎn)的社區(qū) (組) 名 |
| -k | 用于加密的字符串 |
| -K | 用于加密的 Key 文件,和 - k 不能共存 |
| -s | 子網(wǎng)掩碼 |
| -l | supernode 的 IP: 端口,可以指定多個(gè) supernode 的 |
| -i | NAT 打洞間隔 |
| -b | 當(dāng)使用 DHCP 時(shí)定期刷新 IP |
| -p | 指定本地端口 |
| -u | 指定運(yùn)行所用的 UID |
| -g | 指定運(yùn)行所用的 GID |
| -f | 前臺(tái)運(yùn)行 |
| -m | 為虛擬網(wǎng)卡指定 MAC 地址 |
| -r | 啟用包轉(zhuǎn)發(fā),當(dāng) - a 指定 DHCP 時(shí)需要啟用 |
| -E | 接收組播 MAC 地址 |
| -v | 輸出比較詳細(xì)的 log |
| -t | 指定用于管理的 UDP 端口 |
3. 測(cè)試
3.1 ping測(cè)試
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登錄測(cè)試
從PC端ssh登錄到DLAP221設(shè)備:
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. 自啟動(dòng)服務(wù)(可選)
配置 DLAP221節(jié)點(diǎn) edge 服務(wù)腳本
$ 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注冊(cè)服務(wù)并啟動(dòng)服務(wù)
$ 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總結(jié)
以上是生活随笔為你收集整理的使用N2N软件远程管理DLAP221设备的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Leetcode 2029. 石子游戏
- 下一篇: MSR5560 路由器映射