n2n内网穿透神器(一条命令实现穿透)(linux,安卓,win,openwrt全介绍)

n2n简介:

百度百科N2N,内衣服饰品牌于上世纪九十年代在美国诞生,经历逾二十几年的不断拓展,现发展成为庞大的跨国内衣服饰品牌,其连锁专卖店网络遍布全球100多个国家大、中城市,数目逾万间,无论品牌定位、潮流款式都能满足全球广大消费者对优质内衣服饰之需求,是享誉国际的内衣服饰品牌之一。随着中国经济的快速发展和中国消费者对高端内衣服饰需求量的日益增加,并结合N2N全球发展战略的规划,N2N于2012年正式登陆大中华…

什么鬼?

googlen2n is an open source Layer 2 over Layer 3 VPN application which utilises a peer-to-peer architecture for network membership and routing.Unlike many other VPN programs, n2n can also connect computers which reside behind NAT routers. These connections are set up with help from a third computer that both computers can reach. This computer, called a supernode, can then route the information between NATed nodes.[2]It is free software licensed under the terms of the GNU General Public License v3。

好吧,进入正题!


Linux:

n2n的github地址:https://github.com/meyerd/n2n.git

下载下来我们会发现2个版本,这里默认介绍V1版本,已经在linux,安卓,win,openwrt上互通,v2版本未测

Linux下面:git clone https://github.com/meyerd/n2n.git以后,然后进入V1版本编译运行即可

n2n编译完了的命令不是n2n,而是edgesupernode

edge是....怎么形容,就说客户端吧,而supernode则是服务器超级节点,用法也是很简单的,首先看看edge的help:

[html] view plain copy
  1. edge -d <tun device> -a <tun IP address> -c <community> -k <encrypt key> -s <netmask> [-u <uid> -g <gid>][-f][-m <MAC address>]  
  2. -l <supernode host:port> [-p <local port>] [-M <mtu>] [-t] [-r] [-v] [-b] [-h]  
  3.   
  4. -d <tun device>          | tun device name  
  5. -a <tun IP address>      | n2n IP address  
  6. -c <community>           | n2n community name  
  7. -k <encrypt key>         | Encryption key (ASCII) - also N2N_KEY=<encrypt key>  
  8. -s <netmask>             | Edge interface netmask in dotted decimal notation (255.255.255.0)  
  9. -l <supernode host:port> | Supernode IP:port  
  10. -b                       | Periodically resolve supernode IP  
  11.                          | (when supernodes are running on dynamic IPs)  
  12. -p <local port>          | Local port used for connecting to supernode  
  13. -u <UID>                 | User ID (numeric) to use when privileges are dropped  
  14. -g <GID>                 | Group ID (numeric) to use when privileges are dropped  
  15. -f                       | Fork and run as a daemon. Use syslog.  
  16. -m <MAC address>         | Choose a MAC address for the TAP interface  
  17.                          | eg. -m 01:02:03:04:05:06  
  18. -M <mtu>                 | Specify n2n MTU (default 1400)  
  19. -t                       | Use http tunneling (experimental)  
  20. -r                       | Enable packet forwarding through n2n community  
  21. -v                       | Verbose  
具体上面已经介绍的很清楚了,现在实战怎么开启,一句话:
[html] view plain copy
  1. 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 &  
现在简单介绍下上面这条命令的含义,-d edge0就是创建一个虚拟的网卡设备,edge0就是它的名称,-c -k就是用户名和密码,-a虚拟的IP地址,随便取,只要你的所有设备在一个网段即可,然后 -u -g这个是设置UID和GID 也可以不设置,-m 虚拟mac地址,设置了有好处,只要不相同即可,不设置回随机分配,最后有一个重要的地方,-M 1200,这里是设置MTU,至于MTU是什么,可以自行百度哈,没设置之前,ssh,http等协议会卡住死活连不上,设置后就正常了,需要比1400小,安卓上不用设置,这样设置以后就可以ping通你的其他机器了,只要它可以访问到超级节点 -l xx.xx.xx.xx:xxxx

现在介绍supernode,这个是创建超级节点,root权限都不需要,直接supernode -l 端口号,就行了。网上有免费的超级节点,不过都很慢,很卡,很蛋疼,建议自己买个阿里的vps,又便宜,100M宽带一个月32块钱,那速度,只有一个字,飞快,视频在线传输都没问题,我上班都可以通过n2n查看家里的摄像头...

好了,linux下面的就这样,客户端就是那一句话,很方便,开机自动连接,超级节点自己搭建一个,其他机器都可以用这个节点


Windows:

下面介绍win下面怎么搭建n2n:win下面其实也很简单,下个软件设置下就OK了

地址是http://www.hosting.cz/n2nguien.exe提供了一个安装包,里面包含了V1和V2版本,请选择V1版本

 

单击advanced按键,勾选Enable packet forwarding through n2n community,然后其他的自己看,和Linux下的设置一样

 

上面的图借鉴网上的,因为我没在windows下,但是我用的和这个图一样,这里选择V1版本。

把桌面图标拖到菜单启动就可以开机启动了,不要担心,不占内存不占cpu不占网速.....

Android:

下面该介绍安卓了:安卓和win一样,百度上面搜n2n安卓客户端,然后下载安装,注意,需要root权限

下载地址:

[html] view plain copy
  1. 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->->n2n选中即可,或者编辑.config,搜n2n改成=y

或者在板子里面opkg update && opkg install n2n即可

下面看看n2n的配置文件:

[html] view plain copy
  1. config edge                                                                                                                                
  2.     option community 'username'                                                                                                               
  3.     option key 'password'                                                                                                                     
  4.     option port 'port'                                                                                                                                                                                                                                       
  5.     option supernode 'xx.xx.xx.xx'                                                                                                     
  6.     option ipaddr 'xx.xx.xx.xx'                                                                                                            
  7.     option route '1'   

好,现在分析一下配置文件,community就是用户名,key就是密码对应edge命令的-c -k,supernode是超级节点的ip地址,port是端口,对应edge的-l,然后ipaddr是虚拟ip地址,对应-a,route对应-r参数,就是设置是否通过n2n转发,然后我们来看看openwrt下面n2n的服务程序:
[html] view plain copy
  1. start_instance() {  
  2.         local cfg="$1"  
  3.   
  4.         config_get type "$cfg" TYPE  
  5.   
  6.         case "$type" in  
  7.           edge)  
  8.                 config_get ipaddr "$cfg" 'ipaddr'  
  9.                 [ -n "$ipaddr" ] || return 1  
  10.                 config_get supernode "$cfg" 'supernode'  
  11.                 config_get port "$cfg" 'port'  
  12.                 config_get community "$cfg" 'community'  
  13.                 config_get key "$cfg" 'key'  
  14.                 config_get_bool route "$cfg" 'route' '0'  
  15.                 [ "$route" = "1" ] && args='-r'  
  16.                 service_start /usr/sbin/edge -f $args -a $ipaddr -c $community -k $key -l ${supernode}:${port}  
  17.                 ;;  
  18.           supernode)  
  19.                 config_get port "$cfg" port  
  20.                 [ -n "$port" ] || return 1  
  21.                 service_start /usr/sbin/supernode -l $port  
  22.                 ;;  
  23.         esac  
  24. }  
上面是启动的主要函数:首先是读取config 这个type,判断是edge还是supernode如果是supernode则只读取port ,运行命令 supernode -l port,如果type是edge,则读取....等配置文件,然后
[html] view plain copy
  1. edge -f $args -a $ipaddr -c $community -k $key -l ${supernode}:${port}  
上面的 -f是作为一个服务启动,写入syslog

好了这样配置好了就可以访问到路由器的,只要路由器连了外网,就可以随时访问进去

: 经过长期使用,发现一个不美好的问题,如果长时间运行的话,会导致不间断不通不稳定的情况,所以建议每天自动重启一下edge程序

n2n的介绍到此结束,很好很强大的一个功能,基本上人手必备神器,小巧,开源,迅速,免费,无限穿透!

你可能感兴趣的:(Linux杂记)