N2N-V3的安装和配置
一、说明
- 博客日期:2022年1月9日14点23分星期日
- 本次安装配置基于
N2N
的V3
版本,具体区别请参考 N2N版本选择介绍(v1\v2\v2s\v3区别\使用方法教程\免费服务器); - 本次配置主要是以
Linux
为服务端、Windows
为客户端来静态分配地址;
二、环境
(一)节点 A
- 戴尔灵越 7460 笔记本电脑;
- Microsoft Windows10 家庭版 20H2;
- 安装内存 8GB×1 2400MHz;
- CPU:酷睿i5-7200U;
- GPU:核显 Intel HD Graphics 620;
- 远程软件:Xshell 7 个人版、Xftp 7 个人版;
- 连通性测试软件:XNET_V1.2.exe;
- WiFi 分配地址:
192.168.43.115
;
(二)节点 B
- 联想 ideacentre 310-15 台式计算机;
- Microsoft Windows10 家庭版;
- 安装内存:8GB×1 1600MHz;
- CPU:赛扬 J3455;
- GPU:核显 Intel HD Graphics 500;
- 连通性测试软件:XNET_V1.2.exe;
- WiFi 分配地址:
192.168.21.104
;
(三)云服务器实例
- 实例来源:腾讯云
- 实例公网地址:
ccc.ccc.ccc.ccc
- 实例配置:1核 2GB 1Mbps 50GB 高性能云硬盘
- 实例操作系统:Ubuntu 20.04 LTS 64位
- 开放端口:
32221
、32222
三、中转节点配置 (Supernode)
(一)配置端口
- 开放云服务器实例安全组的
32221
、32222
的TCP
和UDP
端口; - 开放实例操作系统内防火墙的
22
、32221
、32222
的TCP
和UDP
端口; - 具体过程请自行上网搜索。
(二)配置docker
-
这里假设
docker
已经安装好了,并且拉取了ubuntu
的镜像,当然如果不用docker
也可以选择跳过这一大步;
-
创建容器,包括后台运行、端口映射、授权等;
sudo docker run -itd -p 32221:32221/tcp -p 32221:32221/udp -p 32222:32222/tcp -p 32222:32222/udp --privileged=true --name ubuntu-n2n-env ubuntu /bin/bash
-
其中,
32221
是作为Manage
端口,而32222
作为主要端口,实测的时候发现32222
端口既需要开放UDP
也需要开放TCP
; -
进入该
ubuntu-n2n-env
容器;
sudo docker exec -it ubuntu-n2n-env /bin/bash
-
更新软件源:
apt-get update
; -
安装
vim
:apt-get install -y vim
; -
修改镜像源:
vim /etc/apt/sources.list
; -
在末尾新增下面内容,接着保存退出:
deb http://mirrors.tencentyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.tencentyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.tencentyun.com/ubuntu/ focal-updates main restricted universe multiverse
#deb http://mirrors.tencentyun.com/ubuntu/ focal-proposed main restricted universe multiverse
#deb http://mirrors.tencentyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.tencentyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.tencentyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.tencentyun.com/ubuntu/ focal-updates main restricted universe multiverse
#deb-src http://mirrors.tencentyun.com/ubuntu/ focal-proposed main restricted universe multiverse
#deb-src http://mirrors.tencentyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
- 再次更新软件源:
apt-get update
; - 安装
git
:apt-get install -y git
; - 安装配置工具:
apt-get install -y autoconf automake libtool make
;
(三)配置 N2N - Supernode
- 进入
home
目录:cd /home/
- 任选下述四个方式之一,克隆
Git
对应仓库到本地:
git clone https://github.com/ntop/n2n
git clone https://github.com.cnpmjs.org/ntop/n2n.git
git clone https://hub.fastgit.org/ntop/n2n.git
git clone https://github.91chi.fun//https://github.com/ntop/n2n.git
- 进入
n2n
目录:cd n2n/
- 依次进行下述每一行命令:
./autogen.sh
./configure
make && make install
- 创建并编辑配置文件:
vim supernode.conf
; - 写入下述内容,然后保存退出:
-p=32222
-t=32221
- 运行
supernode
:supernode ./supernode.conf
; - 使用
ps -ef|grep supernode
命令检查是否在后台运行了supernode
;
四、边缘节点配置 (Edge)
(一)配置 TAP 虚拟网卡
-
这个网卡驱动不好找,建议直接在网上搜索
n2nguien.exe
或n2nguien
,或者试试 这里下载; -
安装期间,会提示要安装虚拟网卡,允许即可;
-
安装完成后,关掉这个软件,我们需要的只是它的驱动;
-
安装完成后,在
适配器选项
中会多出一个下标有TAP-Windows Adapter V9
的适配器,可以重命名该适配器为TAP
,也可以不重命名,影响到后续操作,这里我的是已经连接上了的,正常情况下到了这步,网络还是断开的;
-
找到能上网那个适配器,比如我这里的是WiFi上网,所以适配器名叫
WLAN
,右键点击属性
,再点开共享
,然后勾上允许其他网络用户通过……
,接着选择刚才的TAP虚拟网卡适配器
,确定保存。
(二)配置 N2N-Edge
- 下载已编译好的文件,可以在这里慢慢找,注意要找
Windows
的V3
版本,也可以在这里直接下载; - 解压后发现有4个文件,其中
edge.exe
才是我们所需要的; - 进入该目录,创建并编辑文件
edge.conf
,写入下述内容;
-c=redalert
-l=ccc.ccc.ccc.ccc:32222
-a=192.168.101.11
-d=TAP
-k=123456
-e=auto
-r
其中,-l
是云服务器实例的公网 IPv4 地址和端口号,-a
参数是指定自己虚拟网卡的地址,可以在有限范围内乱编,当然更推荐的是使用自动分配地址,建议先凑合着用静态分配的,-k
参数是密钥,-d
参数是TAP虚拟网卡适配器的名字
,至于其他,照搬过来就好,至于-c
参数,很明显看出是Red Alert 2
了,只有同属一个相同-c
的同网段用户,才能相互访问得到。
注意:这一个配置文件基本内容是相同的,复制到N个主机上,只需要修改-a
参数,使其均在同一个网段下即可。
- 将这一个目录拷贝到节点 A 、节点 B ……
- 进行相同的配置网卡操作,并修改配置文件
edge.
后; - 通过管理员运行的
cmd
命令行,进入当前目录后输入:.\edge.exe .\edge.conf
即可。
五、运行结果
- 连接上中转节点
这里选取了节点 A 的连接过程部分图示,节点 B 同似。(截图的端口是8878
,那是第一次配置遗留的截图,问题不大)
如果连接不上,则会提示下面内容:
WARNING: supernode not responding, now trying [ccc.ccc.ccc.ccc:port]
- 两台主机都打开
XNET.exe
; - 节点 A 作为服务端,设置本机 IP 为
192.168.101.11
,端口为6666
; - 节点 B 作为客户端,设置目标 IP 为
192.168.101.11
,端口为6666
; - 连接后,发送任意内容,证明连通性良好;
当然,最重要的还是方便局域网联机游戏了!
参考文献
[1] Docker容器内部端口映射到外部宿主机端口 - 运维笔记
[2] Docker 容器使用
[3] GitHub - ntop/n2n: Peer-to-peer VPN
[4] 内网穿透之n2n-介绍及使用说明
[5] N2N版本选择介绍(v1\v2\v2s\v3区别\使用方法教程\免费服务器)
[6] GitHub - lucktu/n2n: Provide the binaries(edges and supernodes) of n2n that I collected
[7] N2N使用DHCP方式获取IP地址
END