Ubuntu系统安装和运行n2n
(使用root权限)
下载git
apt install git
下载n2n源码
git clone /meyerd/n2n.git
下载完成之后,当前目录下会出现名为n2n的文件夹:
root@VM-0-15-ubuntu:~# ll n2ntotal 28drwxr-xr-x 5 root root 4096 Jun 23 15:33 ./drwxrwxrwx 21 ubuntu ubuntu 4096 Jun 23 15:33 ../drwxr-xr-x 8 root root 4096 Jun 23 15:33 .git/-rw-r--r-- 1 root root 189 Jun 23 15:33 .gitignoredrwxr-xr-x 6 root root 4096 Jun 23 15:33 n2n_v1/drwxr-xr-x 9 root root 4096 Jun 23 15:33 n2n_v2/-rw-r--r-- 1 root root 783 Jun 23 15:33 README.md
n2n文件夹中同时包含了n2n_v1和n2n_v2两个文件夹。使用cmake编译n2n_v2。
编译安装n2n
安装cmake
n2n_v2的CMakeLists.txt指明cmake最低版本要求是2.6:
root@VM-0-15-ubuntu:~/n2n# more ./n2n_v2/CMakeLists.txtproject(n2n)cmake_minimum_required(VERSION 2.6)# N2n informationset(N2N_VERSION 2.1.0)set(N2N_OSNAME ${CMAKE_SYSTEM})(以下省略)
安装cmake,指定版本不低于2.6
apt install cmake>=2.6
查看cmake版本
root@VM-0-15-ubuntu:~/n2n# cmake --versioncmake version 3.10.2CMake suite maintained and supported by Kitware (/cmake).
编译、安装
cd n2nmkdir -p build_n2n_v2 #创建一个build文件夹,专门用于存放编译生成的文件和目录,#如Makefile、CMakeCache.txt、CMakeFiles#cmake_install.cmake、可执行文件等cd build_n2n_v2cmake ../n2n_v2 #cmakemake && make install #编译、安装
测试
root@VM-0-15-ubuntu:~$ supernode -hsupernode usage-l <lport>Set UDP main listen port to <lport>-f Run in foreground.-u <UID> User ID (numeric) to use when privileges are dropped.-g <GID> Group ID (numeric) to use when privileges are dropped.-v Increase verbosity. Can be used multiple times.-h This help message.
root@VM-0-15-ubuntu:~$ edge -hWelcome to n2n v.2.1.0 for Linux-4.15.0-142-genericBuilt on Jun 15 14:28:22Copyright -09 - edge -d <tun device> -a [static:|dhcp:]<tun IP address> -c <community> [-k <encrypt key> | -K <key file>] [-s <netmask>] [-u <uid> -g <gid>][-f][-m <MAC address>]-l <supernode host:port> [-p <local port>] [-M <mtu>] [-r] [-E] [-v] [-t <mgmt port>] [-b] [-h]-d <tun device>| tun device name-a <mode:address> | Set interface address. For DHCP use '-r -a dhcp:0.0.0.0'-c <community> | n2n community name the edge belongs to.-k <encrypt key> | Encryption key (ASCII) - also N2N_KEY=<encrypt key>. Not with -K.-K <key file> | Specify a key schedule file to load. Not with -k.-s <netmask> | Edge interface netmask in dotted decimal notation (255.255.255.0).-l <supernode host:port> | Supernode IP:port-L <local_ip> | Add local ip to bypass between same nat problem-i <interval> | Set the NAT hole-punch interval (default 20seconds)-b | Periodically resolve supernode IP: (when supernodes are running on dynamic IPs)-p <local port>| Fixed local UDP port.-u <UID> | User ID (numeric) to use when privileges are dropped.-g <GID> | Group ID (numeric) to use when privileges are dropped.-f | Do not fork and run as a daemon; rather run in foreground.-m <MAC address> | Fix MAC address for the TAP interface (otherwise it may be random): eg. -m 01:02:03:04:05:06-M <mtu> | Specify n2n MTU of edge interface (default 1400).-r | Enable packet forwarding through n2n community.-E | Accept multicast MAC addresses (default=drop).-v | Make more verbose. Repeat as required.-t | Management UDP Port (for multiple edges on a machine).Environment variables:N2N_KEY| Encryption key (ASCII). Not with -K or -k.
启动supernode
在终端启动supernode,-f 表示在前台(foreground)运行。不使用 -f 选项,默认在后台运行。
supernode -v -v -v -f
启动edge node
在终端启动supernode,-f 表示在前台(foreground)运行。不使用 -f 选项,默认在后台运行。
edge -v -v -v -d edge0 -a 172.16.32.1 -c ljl -k ljl -l 1.116.255.112:7654 -p 8888 -f