首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 系统运维 >

N2N 相当VPN网络

2013-10-09 
N2N 对等VPN网络n2n是一个二层的虚拟专网,允许用户开发网络中典型的P2P应用而不是在应用层开发。这就意味着

N2N 对等VPN网络
n2n是一个二层的虚拟专网,允许用户开发网络中典型的P2P应用而不是在应用层开发。这就意味着用户可以透明的得到本地地址,只要新的IP地址在一个子网内,无论两台机器处于什么位置都能够ping通对方。

N2N网络的主要特点:

 

  • n2n网络是基于P2P协议的二层加密网络
  • 加密是在节点上完成的,而且使用的是用户的自定义密钥;你控制自己的安全,而不用让比如skype代表你(管理你的服务器节点)
  • 每个n2n用户可以同时属于多个网络
  • 能够反向的穿越NAT和防火墙,因此n2n节点即使在内网也是能够被访问到的,因此防火墙不再是IP级别直接通讯的障碍。
  • n2n网络并没有设计成独立的(自包含的),但是可能能够在n2n和非n2n网络之间路由数据。
    n2n构架是基于两个部分的:
    终端节点:安装在用户计算机上的应用使n2n网络被创建。每个节点设备都会创建一个TUN/TAP虚拟网卡设备作为接入n2n网络的入口点。
    超级节点:作用是使终端节点能够访问到对称防火墙后面的其他终端节点。这个程序是那些无法直接通讯节点的目录记录器和包路由器。

    N2N 相当VPN网络

    从图上可以看出,SuperNode作用是进行转发等通讯,因为其在公网,可以将两个内网的Edge节点连接起来。


    1. #!/bin/sh /etc/rc.common
    2. # Copyright (C) 2008-2012 OpenWrt.org
    3.   
    4. START=90
    5.   
    6. start_instance() {
    7.     local cfg="$1"
    8.   
    9.     config_get type "$cfg" TYPE
    10.   
    11.     case "$type" in
    12.       edge)
    13.         config_get ipaddr "$cfg" 'ipaddr'
    14.         [ -n "$ipaddr" ] || return 1
    15.         config_get supernode "$cfg" 'supernode'
    16.         config_get port "$cfg" 'port'
    17.         config_get community "$cfg" 'community'
    18.         config_get key "$cfg" 'key'
    19.         config_get_bool route "$cfg" 'route' '0'
    20.         [ "$route" = "1" ] && args='-r'
    21.         service_start /usr/sbin/edge -f $args -a $ipaddr -c $community -k $key -l ${supernode}:${port}
    22.         ;;
    23.       supernode)
    24.         config_get port "$cfg" port
    25.         [ -n "$port" ] || return 1
    26.         service_start /usr/sbin/supernode -l $port
    27.         ;;
    28.     esac
    29. }
    30.   
    31. stop_instance() {
    32.     local cfg="$1"
    33.   
    34.     config_get type "$cfg" TYPE
    35.   
    36.     case "$type" in
    37.       edge)
    38.         service_stop /usr/sbin/edge
    39.         ;;
    40.       supernode)
    41.         service_stop /usr/sbin/supernode
    42.         ;;
    43.     esac
    44. }
    45.   
    46. start() {
    47.     config_load 'n2n'
    48.     config_foreach start_instance 'edge'
    49.     config_foreach start_instance 'supernode'
    50. }
    51.   
    52. stop() {
    53.     config_load 'n2n'
    54.     config_foreach stop_instance 'edge'
    55.     config_foreach stop_instance 'supernode'
    56. }

    从对应的启动文件可以看出,使用非常的简单。

    1. config edge
    2.         option ipaddr ''
    3.         option supernode ''
    4.         option port ''
    5.         option community ''
    6.         option key ''
    7.         option route ''
     ipaddr 本地虚拟网卡的地址upsernode 超级节点的地址,可以是域名port 想要使用连接的端口community 对应的网络名称,同一个名称下才能互访key 用户定义的需要访问这边SSH使用的key
    下面的内容是我的两台主机和服务器之间的通讯输出Debug信息

    1. 10/Sep/2013 23:51:47 [ n2n.c: 49] Marshalling hdr: public_ip=(2)0.0.0.0:0, private_ip=(2)0.0.0.0:7654
    2. 10/Sep/2013 23:51:47 [ n2n.c: 638] 84 bytes compressed into 87
    3. 10/Sep/2013 23:51:47 [ n2n.c: 681] ### Tx N2N Msg -> network
    4. 10/Sep/2013 23:52:17 [ n2n.c: 843] Purging old registrations
    5. 10/Sep/2013 23:52:17 [ n2n.c: 848] Remove 0 registrations
    6. 10/Sep/2013 23:52:22 [ n2n.c: 49] Unmarshalled hdr: public_ip=(2)0.0.0.0:0, private_ip=(2)0.0.0.0:50000
    7. 10/Sep/2013 23:52:22 [ n2n.c: 540] +++ Received unreliable data packet [rcvd_from=60.215.250.204:50000][msg_type=MSG_TYPE_REGISTER][seq_id=0]
    8. 10/Sep/2013 23:52:22 [ n2n.c: 545] [src_mac=DE:AD:BE:EF:01:23][dst_mac=00:00:00:00:00:00][original_sender=0.0.0.0:0]
    9. 10/Sep/2013 23:52:22 [supernode.c: 312] Received message from node [60.215.250.204:-15536]
    10. 10/Sep/2013 23:52:22 [ n2n.c: 49] Unmarshalled hdr: public_ip=(2)60.215.250.204:50000, private_ip=(2)0.0.0.0:50000
    11. 10/Sep/2013 23:52:22 [ n2n.c: 49] Marshalling hdr: public_ip=(2)0.0.0.0:0, private_ip=(2)0.0.0.0:7654
    12. 10/Sep/2013 23:52:22 [ n2n.c: 49] Unmarshalled hdr: public_ip=(2)0.0.0.0:0, private_ip=(2)0.0.0.0:7654
    13. 10/Sep/2013 23:52:22 [ n2n.c: 736] Sent unreliable packet [msg_type=MSG_TYPE_REGISTER_ACK][seq_id=0][src_mac=00:00:00:00:00:00][dst_mac=DE:AD:BE:EF:01:23]
    14. 10/Sep/2013 23:52:22 [ n2n.c: 49] Marshalling hdr: public_ip=(2)0.0.0.0:0, private_ip=(2)0.0.0.0:7654
    15. 10/Sep/2013 23:52:22 [ n2n.c: 638] 84 bytes compressed into 87
    16. 10/Sep/2013 23:52:22 [ n2n.c: 681] ### Tx N2N Msg -> network
    17. 10/Sep/2013 23:52:47 [ n2n.c: 49] Unmarshalled hdr: public_ip=(2)0.0.0.0:0, private_ip=(2)0.0.0.0:50001
    18. 10/Sep/2013 23:52:47 [ n2n.c: 540] +++ Received unreliable data packet [rcvd_from=60.215.250.204:50001][msg_type=MSG_TYPE_REGISTER][seq_id=0]
    19. 10/Sep/2013 23:52:47 [ n2n.c: 545] [src_mac=DE:AD:BE:EF:01:24][dst_mac=00:00:00:00:00:00][original_sender=0.0.0.0:0]
    20. 10/Sep/2013 23:52:47 [supernode.c: 312] Received message from node [60.215.250.204:-15535]
    21. 10/Sep/2013 23:52:47 [ n2n.c: 49] Unmarshalled hdr: public_ip=(2)60.215.250.204:50001, private_ip=(2)0.0.0.0:50001
    22. 10/Sep/2013 23:52:47 [ n2n.c: 49] Marshalling hdr: public_ip=(2)0.0.0.0:0, private_ip=(2)0.0.0.0:7654
    23. 10/Sep/2013 23:52:47 [ n2n.c: 49] Unmarshalled hdr: public_ip=(2)0.0.0.0:0, private_ip=(2)0.0.0.0:7654
    24. 10/Sep/2013 23:52:47 [ n2n.c: 736] Sent unreliable packet [msg_type=MSG_TYPE_REGISTER_ACK][seq_id=0][src_mac=00:00:00:00:00:00][dst_mac=DE:AD:BE:EF:01:24]
    25. 10/Sep/2013 23:52:47 [ n2n.c: 49] Marshalling hdr: public_ip=(2)0.0.0.0:0, private_ip=(2)0.0.0.0:7654
    26. 10/Sep/2013 23:52:47 [ n2n.c: 638] 84 bytes compressed into 87
    27. 10/Sep/2013 23:52:47 [ n2n.c: 681] ### Tx N2N Msg -> network

热点排行