n2n內網穿透神器(一條命令實現穿透)(linux,安卓,win,openwrt全介紹)
n2n簡介:
百度百科:N2N,內衣服飾品牌於上世紀九十年代在美國誕生,經歷逾二十幾年的不斷拓展,現發展成為龐大的跨國內衣服飾品牌,其連鎖專賣店網路遍佈全球100多個國家大、中城市,數目逾萬間,無論品牌定位、潮流款式都能滿足全球廣大消費者對優質內衣服飾之需求,是享譽國際的內衣服飾品牌之一。隨著中國經濟的快速發展和中國消費者對高階內衣服飾需求量的日益增加,並結合N2N全球發展戰略的規劃,N2N於2012年正式登陸大中華…
什麼鬼?
google:n2n is
an open source Layer 2 over Layer 3VPN application
which utilises a peer-to-peer
好吧,進入正題!
Linux:
下載下來我們會發現2個版本,這裡預設介紹V1版本,已經在linux,安卓,win,openwrt上互通,v2版本未測
Linux下面:git clone https://github.com/meyerd/n2n.git以後,然後進入V1版本編譯執行即可
n2n編譯完了的命令不是n2n,而是edge和supernode
edge是....怎麼形容,就說客戶端吧,而supernode則是伺服器超級節點,用法也是很簡單的,首先看看edge的help:
- edge -d <tun device> -a <tun IP address> -c <community> -k <encrypt key> -s <netmask> [-u <uid> -g <gid>][-f][-m <MAC address>]
- -l <supernode host:port> [-p <local port>] [-M <mtu>] [-t] [-r] [-v] [-b] [-h]
- -d <tun device> | tun device name
- -a <tun IP address> | n2n IP address
- -c <community> | n2n community name
- -k <encrypt key> | Encryption key (ASCII) - also N2N_KEY=<encrypt key>
- -s <netmask> | Edge interface netmask in dotted decimal notation (255.255.255.0)
- -l <supernode host:port> | Supernode IP:port
- -b | Periodically resolve supernode IP
- | (when supernodes are running on dynamic IPs)
- -p <local port> | Local port used for connecting to supernode
- -u <UID> | User ID (numeric) to use when privileges are dropped
- -g <GID> | Group ID (numeric) to use when privileges are dropped
- -f | Fork and run as a daemon. Use syslog.
- -m <MAC address> | Choose a MAC address for the TAP interface
- | eg. -m 01:02:03:04:05:06
- -M <mtu> | Specify n2n MTU (default 1400)
- -t | Use http tunneling (experimental)
- -r | Enable packet forwarding through n2n community
- -v | Verbose
- sudo edge -d edge0 -a xx.xx.xx.xx -c username -u 1000 -g 1000 -M 1200 -k password -l xx.xx.xx.xx:xxxx -m 41:03:05:00:10:01 > /dev/null &
現在介紹supernode,這個是建立超級節點,root許可權都不需要,直接supernode -l 埠號,就行了。網上有免費的超級節點,不過都很慢,很卡,很蛋疼,建議自己買個阿里的vps,又便宜,100M寬頻一個月32塊錢,那速度,只有一個字,飛快,視訊線上傳輸都沒問題,我上班都可以通過n2n檢視家裡的攝像頭...
好了,linux下面的就這樣,客戶端就是那一句話,很方便,開機自動連線,超級節點自己搭建一個,其他機器都可以用這個節點
Windows:
下面介紹win下面怎麼搭建n2n:win下面其實也很簡單,下個軟體設定下就OK了
單擊advanced按鍵,勾選Enable packet forwarding through n2n community,然後其他的自己看,和Linux下的設定一樣
上面的圖借鑑網上的,因為我沒在windows下,但是我用的和這個圖一樣,這裡選擇V1版本。
把桌面圖示拖到選單啟動就可以開機啟動了,不要擔心,不佔記憶體不佔cpu不佔網速.....
Android:
下面該介紹安卓了:安卓和win一樣,百度上面搜n2n安卓客戶端,然後下載安裝,注意,需要root許可權
下載地址:
- http://download.csdn.net/detail/leekwen/8604177
設定好了點選start,出現RX什麼ACK就表示連通了,可以用超級終端ping通,或者ssh連線
其實安卓上有arm linux,不過不好打字,我現在也沒怎麼用,在arm linux裡面你可以下載更新和pc一樣,還可以vnc進桌面。
好了,安卓版就說到這裡了。
OpenWrt:
下面介紹OpenWrt的n2n配置,這些都是很有價值的,具體價值自己去想
首先安裝n2n,可以編譯的時候編譯進去。make menuconfig裡面找到network->vpn->n2n選中即可,或者編輯.config,搜n2n改成=y
或者在板子裡面opkg update && opkg install n2n即可
下面看看n2n的配置檔案:
- config edge
- option community 'username'
- option key 'password'
- option port 'port'
- option supernode 'xx.xx.xx.xx'
- option ipaddr 'xx.xx.xx.xx'
- option route '1'
好,現在分析一下配置檔案,community就是使用者名稱,key就是密碼對應edge命令的-c -k,supernode是超級節點的ip地址,port是埠,對應edge的-l,然後ipaddr是虛擬ip地址,對應-a,route對應-r引數,就是設定是否通過n2n轉發,然後我們來看看openwrt下面n2n的服務程式:
- start_instance() {
- local cfg="$1"
- config_get type "$cfg" TYPE
- case "$type" in
- edge)
- config_get ipaddr "$cfg" 'ipaddr'
- [ -n "$ipaddr" ] || return 1
- config_get supernode "$cfg" 'supernode'
- config_get port "$cfg" 'port'
- config_get community "$cfg" 'community'
- config_get key "$cfg" 'key'
- config_get_bool route "$cfg" 'route' '0'
- [ "$route" = "1" ] && args='-r'
- service_start /usr/sbin/edge -f $args -a $ipaddr -c $community -k $key -l ${supernode}:${port}
- ;;
- supernode)
- config_get port "$cfg" port
- [ -n "$port" ] || return 1
- service_start /usr/sbin/supernode -l $port
- ;;
- esac
- }
- edge -f $args -a $ipaddr -c $community -k $key -l ${supernode}:${port}
好了這樣配置好了就可以訪問到路由器的,只要路由器連了外網,就可以隨時訪問進去
注 :
經過長期使用,發現一個不美好的問題,如果長時間執行的話,會導致不間斷不通不穩定的情況,所以建議每天自動重啟一下edge程式!
n2n的介紹到此結束,很好很強大的一個功能,基本上人手必備神器,小巧,開源,迅速,免費,無限穿透!