日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用N2N,实现异地快速组建内网

發布時間:2023/12/18 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用N2N,实现异地快速组建内网 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

工作中管理多地分公司辦事處網絡訪問,經常遇到一個問題:

  • 想要在分公司之間組建一個局域網,專線費用太高;
  • 使用傳統的VPN技術,所有的流量轉發壓力全集中在一臺服務器不說,如果VPN服務器崩潰了,整個局域網都會崩潰;
  • 使用第三方VPN服務,機密數據流量安全問題無法保障;
  • 墻,墻,墻,部分VPN過墻就被攔截,根本無法進行透傳;

隨著P2P網絡模式的流行,與之而來衍生出了一種新的概念:P2P VPN。

1. 什么是P2P VPN

P2P VPN 是一個 VPN 模型,它能解決傳統的基于服務器-客戶端模型的 VPN 存在的這些問題。一個 P2P VPN 中不再有一個中心的 VPN 服務器,任何擁有一個公開 IP 地址的節點都能引導其他節點進入 VPN。當連接到一個 VPN 之后,每一個節點都能與 VPN 中的任何其他節點直接通信,而不需要經過一個中間的服務器節點。當然任何節點出現故障時,VPN 中的剩余節點不會受到影響。節點中的延遲、帶寬以及 VPN 擴展性在這樣的設定中都有自然的提升。

一個傳統的 VPN(如 OpenVPN、PPTP)由一個 VPN 服務器和一個或多個連接到這臺服務器的客戶端組成。當任意兩個 VPN 客戶端彼此通信時,VPN 服務器需要中繼它們之間的 VPN 數據流量。這樣一個中心輻射型的 VPN 拓撲結構存在的問題是,當連接的客戶端增多以后,VPN 服務器很容易成為一個性能上的瓶頸。從某種意義上來說,中心化的 VPN 服務器也同樣成為一個單點故障的來源,也就是當 VPN 服務器出現故障的時候,整個 VPN 都將無法被任何 VPN 客戶端訪問。

開源的 P2P VPN 實現已經有幾個了,比如 Tinc、peerVPN,以及 n2n。

2. 部署教程

我們將使用?N2N來完成本篇教程。N2N目前有多個版本,v1版本、v2版本v2s版本。

v1版本

此版本為官方N2N項目v1版本的修改版,最后一次commit距今已有3年時間,已被淘汰

項目:https://github.com/meyerd/n2n/tree/master/n2n_v1

v2版本

目前最常用的版本,也是官方N2N項目重啟后,在各路大神的貢獻下,一直在維護并不斷完善的版本

項目:https://github.com/ntop/n2n

v2s版本

此版本可以為官方N2N項目v2版本(v2項目重啟前)的修改版,最后一次commit距今已有2年時間,極小部分用戶仍在使用

項目:https://github.com/meyerd/n2n/tree/master/n2n_v2

本次使用v2 dev 分支版本搭建(注:git最新dev分支兼容性較差,不推薦使用舊版edge(客戶端)連接新版supernode(服務端)

這里在centos7.X下編譯N2N為例,該版本支持自動分配IP

?

yum install autoconf automake libtool git -y git clone https://github.com/ntop/n2n.git -b dev cd n2n/ ./autogen.sh ./configure make && make install

啟動supernode服務器(最好有公網IP,沒有公網IP也可以通過防火墻NAT端口),只有一行命令

supernode -l xxx #XXX為端口號

參數說明
-p <port> ? ? ? ? | Set UDP main listen port to <port>
-c <path> ? ? ? ? | File containing the allowed communities.
-l <sn host:port> | Name/IP of a known supernode:port.
-F <fed_name> ? ? | Name of the supernodes federation (otherwise use '*Federation' by default)
-u <UID> ? ? ? ? ?| User ID (numeric) to use when privileges are dropped.
-g <GID> ? ? ? ? ?| Group ID (numeric) to use when privileges are dropped.
-t <port> ? ? ? ? | Management UDP Port (for multiple supernodes on a machine).
-a <net-net/bit> ?| Subnet range for auto ip address service, e.g.
? ? ? ? ? ? ? ? ? | -a 192.168.0.0-192.168.255.0/24, defaults to 10.128.255.0-10.255.255.0/24
-v ? ? ? ? ? ? ? ?| Increase verbosity. Can be used multiple times.
-h ? ? ? ? ? ? ? ?| This help message.

服務端如開啟iptables\firewalld等防火墻,需要放行supernode所設置的端口,否則客戶端無法連接

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

客戶端

安裝步驟與supernode服務器相同

配置內網節點

1.內網啟動edge,可以手動啟動或者加入到開機腳本。
2.內網節點開啟路由轉發
windows系統:將內網網卡開啟共享,共享目標為虛擬的TAP網卡就可以開啟路由。
Linux系統:開啟防火墻的端口轉發功能。

edge -d edge0 -a 本節點IP -s 子網掩碼 -m MAC地址(最好指定) -c 分組名 -k 密碼 -l supernode地址:端口 -b -r -E -f例 edge -d edge0 -a 10.206.108.200 -s 255.255.255.0 -c n2n -k pass -l xxx.xxx.xxx.xxx:3389 -b -r -E -f -m xx:xx:xx:xx:xx:xx

參數說明

-d <tap device> ? ? ? ? ?| tap device name
-a [mode:]<address>[/nn] | Interface address and optional subnet (cidr, default /24). 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>.
-l <supernode host:port> | Supernode IP:port
-i <reg_interval> ? ? ? ?| Registration interval, for NAT hole punching (default 20 seconds)
-I <device description> ?| Annotate the edge's description (hint), identified in the manage port
-L <reg_ttl> ? ? ? ? ? ? | TTL for registration packet when UDP NAT hole punching through supernode (default 0 for not set )
-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 1290).
-D ? ? ? ? ? ? ? ? ? ? ? | Enable PMTU discovery. PMTU discovery can reduce fragmentation but
? ? ? ? ? ? ? ? ? ? ? ? ?| causes connections stall when not properly supported.
-r ? ? ? ? ? ? ? ? ? ? ? | Enable packet forwarding through n2n community.
-A1 ? ? ? ? ? ? ? ? ? ? ?| Disable payload encryption. Do not use with key (defaulting to AES then).
-A2 ... -A5 or -A ? ? ? ?| Choose a cipher for payload encryption, requires a key: -A2 = Twofish,
? ? ? ? ? ? ? ? ? ? ? ? ?| -A3 or -A (deprecated) = AES (default), -A4 = ChaCha20, -A5 = Speck-CTR.
-H ? ? ? ? ? ? ? ? ? ? ? | Enable full header encryption. Requires supernode with fixed community.
-z1 ... -z2 or -z ? ? ? ?| Enable compression for outgoing data packets: -z1 or -z = lzo1x (default=disabled).
-E ? ? ? ? ? ? ? ? ? ? ? | Accept multicast MAC addresses (default=drop).
-S ? ? ? ? ? ? ? ? ? ? ? | Do not connect P2P. Always use the supernode.
-T <tos> ? ? ? ? ? ? ? ? | TOS for packets (e.g. 0x48 for SSH like priority)
-n <cidr:gateway> ? ? ? ?| Route an IPv4 network via the gw. Use 0.0.0.0/0 for the default gw. Can be set multiple times.
-v ? ? ? ? ? ? ? ? ? ? ? | Make more verbose. Repeat as required.
-R <rule_str> ? ? ? ? ? ?| Drop or accept packets by rules. Can be set multiple times.
? ? ? ? ? ? ? ? ? ? ? ? ?| Rule format: src_ip/len:[b_port,e_port],dst_ip/len:[s_port,e_port],TCP+/-,UDP+/-,ICMP+/-
-t <port> ? ? ? ? ? ? ? ?| Management UDP Port (for multiple edges on a machine).
先寫這么多,備忘

總結

以上是生活随笔為你收集整理的使用N2N,实现异地快速组建内网的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。