How to Run N2N on CentOS 7 — Edge Edition
边缘节点(node):The node that will become part of the virtual network.
Precompiled Binaries
Build environment: CentOS Linux release 7.9.2009 (Core) Linux version 3.10.0-1160.11.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Fri Dec 18 16:34:56 UTC 2020
yum install openssl
wget https://download.margrop.net/d/oneindex/network/n2n_2.8_stable/CentOS7/edge -O edge
Manual Edge Startup
- Grant executable permissions
If you downloaded the executable directly, copy it to the path below
chmod +x /usr/local/sbin/edge
- Test if it starts normally
Note: For the
-a-c-k-lparameters below, modify them according to your requirements
edge -d h0 -a 10.0.0.1 -c margrop -k UFDMIlrK3ueQz5mS -l blog.margrop.net:2345 -r -v -f
- Edge parameter brief explanations; for detailed explanations, run edge directly on the command line
| Parameter name | English | Chinese | Example |
|---|---|---|---|
| -d | tun device | Virtual network interface name | -d h0 |
| -a | Set interface address. For DHCP use ‘-r -a dhcp:0.0.0.0’ | Virtual IP | -a 10.0.0.1 |
| -c | n2n community name the edge belongs to. | Community name (i.e., virtual network username) | -c margrop |
| -k | Encryption key (ASCII) - also N2N_KEY=. | Community password (i.e., virtual network password) | -k UFDMIlrK3ueQz5mS |
| -l | Supernode IP:port | Supernode address, domain:port or IP:port | -l blog.margrop.net:2345 |
| -r | Enable packet forwarding through n2n community. | Enable packet forwarding through n2n Community. | -r |
| -v | Make more verbose. Repeat as required. | Enable verbose mode, print more logs | -v |
| -f | do not fork and run as a daemon; rather run in foreground. | Do not fork and run as a daemon; run in foreground instead | -f |
Auto-start Edge
- Edit the systemctl startup file
vim /etc/systemd/system/edge.service
[Unit]
Description=N2N Edge Run On Port 2012 UDP
After=supernode.target
[Service]
Type=simple
ExecStart=/usr/local/sbin/edge -a 10.0.0.1 -c margrop -k UFDMIlrK3ueQz5mS -l blog.margrop.net:2345 -r -v -f
TimeoutStartSec=0
[Install]
WantedBy=supernode.target
- Start the service
systemctl daemon-reload
systemctl stop edge
systemctl start edge
systemctl status edge
- Enable automatic startup
systemctl enable edge
The following are optional settings; skip if unclear
- Enable IP forwarding on CentOS
vim /etc/sysctl.conf
Add this line
net.ipv4.ip_forward = 1
Reload sysctl
sysctl -p
- Configure CentOS routing table
(重要:不能加入自己本地的网段路由)
route del -net 192.168.1.0 netmask 255.255.255.0 gw 10.0.0.1
route add -net 192.168.1.0 netmask 255.255.255.0 gw 10.0.0.1
route del -net 192.168.103.0 netmask 255.255.255.0 gw 10.0.0.103
route add -net 192.168.103.0 netmask 255.255.255.0 gw 10.0.0.103
route del -net 192.168.113.0 netmask 255.255.255.0 gw 10.0.0.113
route add -net 192.168.113.0 netmask 255.255.255.0 gw 10.0.0.113
- Open Firewalld and enable NAT functionality
firewall-cmd --set-default-zone=public
firewall-cmd --permanent --zone=public --change-interface=sh0
firewall-cmd --permanent --zone=public --add-masquerade
firewall-cmd --zone=public --list-all
firewall-cmd --reload
firewall-cmd --list-all
firewall-cmd --get-active-zones