使用N2N搭建虚拟局域网联机游戏(服务端)

N2N, 分享, 折腾 2018/04/14

客户端

本站已搭建免费公益N2N服务端,并制作了N2N的启动器,如需直接联机游戏,请移步:

使用N2N搭建虚拟局域网联机游戏(客户端)

服务端(Linux)

以下安装编译基于CentOS 7 64bit,版本为n2n 3.0.0尽量使用同版本服务端和客户端,避免发生兼容性问题,导致无法连接

注:以下安装方式二选一

RPM安装

yum install libzstd -y
wget https://github.com/ntop/n2n/releases/download/3.0/n2n-3.0.0-1038.x86_64.rpm
rpm -i n2n-3.0.0-1038.x86_64.rpm

编译安装

编译环境

#CentOS
yum install autoconf automake libtool git kernel-headers -y
#Ubuntu
apt-get install autoconf make gcc -y

开始编译

wget https://github.com/ntop/n2n/archive/refs/tags/3.0.tar.gz
tar xzvf 3.0.tar.gz
cd n2n-3.0
./autogen.sh
./configure
make && make install

启动服务端

详细的服务端参数见这里 EasyN2N 服务端(Supernode)附加参数

#实际使用时,可以去掉 -f 参数,使其后台运行
supernode -p 9527 -f

若服务器开启了如iptables\firewalld\ufw等防火墙,需要放行supernode所设置的端口,否则客户端无法连接

#firewalld
firewall-cmd --zone=public --add-port=9527/udp --permanent
firewall-cmd --reload
#iptables
iptables -I INPUT -p udp --dport 9527 -j ACCEPT
service iptables save
service iptables restart
#ufw
ufw allow 9527/udp

另外,如果使用的阿里云、腾讯云等云服务器,还需要单独再在安全组中放行使用的端口(UDP)

服务端(Windows)

下载 EasyN2N,界面菜单中打开服务端

选择服务端的版本(默认v3,推荐v3),一键启动

详细的服务端参数见这里 EasyN2N 服务端(Supernode)附加参数

和Linux端类似,开启了Windows防火墙的机器需要注意放行指定的端口,或关闭防火墙

另外,如果使用的阿里云、腾讯云等云服务器,还需要单独再在安全组中放行使用的端口(UDP)



265 条评论

  • doge24190 评论于 回复

    这个软件实在是太方便了,感谢大佬!
    大佬一个人维护起来想必很辛苦吧,有没有考虑将这个软件开源后让社群维护呢?

  • knwggld 评论于 回复

    各位大佬好,请问如何在linux服务端关闭端口,比武我现在开启了9527和11111这两个端口,想要关闭9527,仅使用11111这个端口,请问是否有具体的命令实现,我看服务端参数并没有给出答案

    • knwggld 评论于 回复

      @knwggld
      我指的是,除了kill掉9527那个进程之外,还有没有其他方式关闭端口

      • Bug侠 评论于 回复

        @knwggld
        11111是什么端口?

        • knwggld 评论于 回复

          @Bug侠
          11111就只是我想替换掉9527的端口,就是我个人不想用默认端口,但是当时已经开启了9527,当时找了参数后没用索性直接kill掉了9527的那个进程,目前用的很舒服,已经不需要了,谢谢回复

  • Ca 评论于 回复

    大佬我这有公网ip用自己电脑当服务端怎么连接不上啊

    • 提耶利亚 评论于 回复

      @Ca
      路由器设置端口转发你的服务端设置的端口

  • 提耶利亚 评论于 回复

    如果自己有公网IP 可以用自己电脑当服务端吗

  • Aldrich 评论于 回复

    买了一个1核0.5g内存的服务器,只挂frp和n2n服务器够用吗

  • 369 评论于 回复

    中root@localhost:~
    X
    Using use rname ” root”,
    Last login: Sun DeC 10 13:52:30 2023 from 120.232.88.109
    [root@localhost ~]# supernode -p 10888 -f
    10/Dec/2023 15:30:29 [supernode .c:588] WARNING: using default federation name; F
    OR TESTING ONLY, usage of a custom federation name (-F) is highly recommended !
    10/Dec/2023 15:30:29 [sn_ utils.c:136] calculated shared secrets for edge authent
    i cation
    10/Dec/2023 15:30:29 [supernode.c: 604] supernode is listening on UDP 10888 (main
    10/Dec/2023 15:30:29 [supe rnode .c:613] supernode opened TCP 10888 (aux)
    10/Dec/2023 15:30:29 [supe rnode .c:620] supernode is listening on TCP 10888 (aux)
    10/Dec/2023 15:30:29 [supe rnode .c:629] supernode is listening on UDP 5645 (manag
    | ement)
    10/Dec/2023 15:30:29 [supernode.c:641] dropping privileges to uid=99, gid=99
    10/Dec/2023 15:30:29 [sn utils.c:807] successfully created resolver thread
    I 10/Dec/2023 15:30:29 [supernode .c:659] supernode started
    我想问问这都启动成功了 为啥获取不了IP呢

  • kukuman 评论于 回复

    我用的centos搭建的服务器,是按照上面的步骤做的,中间没有提示错误。状态如下:
    ARNING: using default federation name; FOR TESTING ONLY, usage of a custom federation name (-F) is highly recommended!
    10/Dec/2023 11:23:37 [sn_utils.c:136] calculated shared secrets for edge authentication
    10/Dec/2023 11:23:37 [supernode.c:604] supernode is listening on UDP 3149 (main)
    10/Dec/2023 11:23:37 [n2n.c:56] ERROR: Bind error on local port 3149 [Address already in use]
    10/Dec/2023 11:23:37 [supernode.c:610] ERROR: failed to open auxiliary TCP socket, Address already in use
    但是客户端连接的时候,其他都正常,就是没有 ok 那一项,日志如下:
    [2023-12-10 11:24:59] adding supernode = 115.159.69.11:3139
    [2023-12-10 11:24:59] starting n2n edge 3.1.1-16-g23e168b-dirty-r1200 x64_static May 8 2022 23:45:52
    [2023-12-10 11:24:59] using compression: none.
    [2023-12-10 11:24:59] using null cipher.
    [2023-12-10 11:24:59] number of supernodes in the list: 1
    [2023-12-10 11:24:59] supernode 0 => 115.159.69.11:3139
    [2023-12-10 11:24:59] WARNING: encryption is disabled in edge
    [2023-12-10 11:24:59] successfully created resolver thread
    [2023-12-10 11:24:59] successfully created port mapping thread
    [2023-12-10 11:24:59] use manually set IP address
    [2023-12-10 11:24:59] created local tap device IP: 192.168.8.9, Mask: 255.255.255.0, MAC: 00:FF:1F:E2:52:CF
    [2023-12-10 11:24:59] edge started
    [2023-12-10 11:24:59] successfully joined multicast group 224.0.0.68:1968
    [2023-12-10 11:25:01] WARNING: NAT-PMP invalid response type 42176
    [2023-12-10 11:25:09] WARNING: no IGD UPnP device found on the network
    [2023-12-10 11:25:11] WARNING: supernode not responding, now trying [115.159.69.11:3139]
    建了两个客户端,就是ping不通。换免费的服务器是可以ping通的
    我用的是腾讯云,安全组我也去设置了,但是不知道生效了没有,按道理是可以的。
    谢谢了

    • Bug侠 评论于 回复

      @kukuman
      服务端的这一行:
      ERROR: failed to open auxiliary TCP socket, Address already in use
      你指定的3149端口被占用了,两种可能:
      1.3149被其他程序占用
      2.后台已经有一个supernode程序在运行

      • kukuman 评论于 回复

        @Bug侠
        您好,非常感谢您的答复。我重新设置的端口,状态如下:(对照了免费服务器记录的应该是正常的)
        [root@VM-16-11-centos ~]# supernode -p 9527 -f
        10/Dec/2023 17:24:43 [supernode.c:588] WARNING: using default federation name; FOR TESTING ONLY, usage of a custom federation name (-F) is highly recommended!
        10/Dec/2023 17:24:43 [sn_utils.c:136] calculated shared secrets for edge authentication
        10/Dec/2023 17:24:43 [supernode.c:604] supernode is listening on UDP 9527 (main)
        10/Dec/2023 17:24:43 [supernode.c:613] supernode opened TCP 9527 (aux)
        10/Dec/2023 17:24:43 [supernode.c:620] supernode is listening on TCP 9527 (aux)
        10/Dec/2023 17:24:43 [supernode.c:629] supernode is listening on UDP 5645 (management)
        10/Dec/2023 17:24:43 [supernode.c:641] dropping privileges to uid=99, gid=99
        10/Dec/2023 17:24:43 [sn_utils.c:807] successfully created resolver thread
        10/Dec/2023 17:24:43 [supernode.c:659] supernode started
        客户端:还是没有OK那一项
        [2023-12-10 17:30:24] adding supernode = 115.159.69.11:9527
        [2023-12-10 17:30:24] starting n2n edge 3.1.1-16-g23e168b-dirty-r1200 x64_static May 8 2022 23:45:52
        [2023-12-10 17:30:24] using compression: none.
        [2023-12-10 17:30:24] using null cipher.
        [2023-12-10 17:30:24] number of supernodes in the list: 1
        [2023-12-10 17:30:24] supernode 0 => 115.159.69.11:9527
        [2023-12-10 17:30:24] WARNING: encryption is disabled in edge
        [2023-12-10 17:30:24] successfully created resolver thread
        [2023-12-10 17:30:24] successfully created port mapping thread
        [2023-12-10 17:30:24] use manually set IP address
        [2023-12-10 17:30:24] created local tap device IP: 192.168.8.9, Mask: 255.255.255.0, MAC: 00:FF:1F:E2:52:CF
        [2023-12-10 17:30:24] edge started
        [2023-12-10 17:30:24] successfully joined multicast group 224.0.0.68:1968
        [2023-12-10 17:30:26] WARNING: NAT-PMP invalid response type 42176
        [2023-12-10 17:30:34] WARNING: UPnP get external ip address failed, code -1 (Miniupnpc Unknown Error)
        [2023-12-10 17:30:34] WARNING: UPnP local TCP port 54044 mapping failed, code -1 (Miniupnpc Unknown Error)
        [2023-12-10 17:30:34] WARNING: UPnP local UDP port 54044 mapping failed, code -1 (Miniupnpc Unknown Error)
        [2023-12-10 17:30:36] WARNING: supernode not responding, now trying [115.159.69.11:9527]
        麻烦再帮我看一下,谢谢了!

    • kukuman 评论于 回复

      @kukuman
      哦,解决了。在腾讯云的防火墙哪里设置了就好了。谢谢了!!!

    • Aldrich 评论于 回复

      @kukuman
      你服务器都没开上,端口被占用了,你先查询你的3149端口开了什么,把进程kill掉,在重新监听这个端口

  • 黑夜守望者 评论于 回复

    开启supernode的主机如何开edge自连:
    我的宽带有外网ip,家中有数台电脑通过路由器访问网络,其中一台电脑开启了supernode,在将udp端口在路由器上做了映射后外网可以连接 supernode组VPN,但是本机开启edge后用”外网ip:端口”无法连接自己本机上开启的supernode,请问有没有办法让开了supernode的机子可以加入本VPN?

    • Bug侠 评论于 回复

      @黑夜守望者
      同在一个内网下的设备可以通过【内网IP:端口】来连接,本机既是supernode又是edge,则可以直接【127.0.0.1:端口】来连接

  • 233 评论于 回复

    我注意到这个软件是基于以GPLV3协议开源的n2n制作的,那么根据GPLV3的传染性要求,easyn2n是否需要以GPLV3开源呢?

  • md 评论于 回复

    大佬,什么时候支持docker部署啊

  • 评论(本站已开启评论回复邮件通知功能,请如实填写邮箱以便及时收到回复)