N2N: vpn p2p

n2n

n2n crea una rete lan virtuale, senza far passare il traffico tramite un server “centro stella”, ma direttamente tra i client. E’ necessario un supernodo (con ip e porta noti) che permetta ai client (detti nodi edge) di scambiarsi informazioni su come  raggiungere gli altri client (ip e porte con cui vengono proiettati su Internet).

Ho a lungo cercato alternative ad Hamachi, multipiattaforma, opensource e vpn con traffico decentralizzato (p2p): a parte tinc (http://www.tinc-vpn.org/) che funziona in modo completamente diverso, n2n è la soluzione migliore che abbia trovato.

Il software è stato sviluppato da Luca Deri e Richard Andrews nel 2008, non più supportato, ma esiste un fork di Costin Lupu che ha corretto alcuni bug e implementato alcune funzioni in cantiere.
Vi sono funzioni nascoste (va analizzto il codice) come il multi-supernodo (cluster di supernodi) e il dhcp da aprte del supernodo (per non assegnare a mano gli indirizzi ip).

Qui si puo’ scaricare il sorgente ed eseguibili per Windows: http://www.ntop.org/get-started/download/
(
non piu disponibile)

La versione Windows con Gui (la migliore che abbia provata è la versione cieca)
http://www.vpnhosting.cz/wiki/index.php/N2n_Gui_En

20151109_Selezione_002

Esiste la versione MAC e la versione Android (richiede root perchè non usa le API comuni di Android vpn ): https://play.google.com/store/apps/details?id=org.zhoubug.n2n_gui

n2n v1 è presente nei repository Debian, attenzione però che non è compatibile con la v2.

Slides di Luca Deri: https://www.terena.org/activities/ngn-ws/ws2/deri-n2n.pdf

Scripts per n2n: https://github.com/jakm/n2n-scripts

La wiki page di Ubuntu (ma per versione 1); http://manpages.ubuntu.com/manpages/precise/man8/edge.8.html

Binari per Linux compilati da me:

git clone https://github.com/bizzarrone/n2n_v2_DebianBinaries.git


A Layer Two Peer-to-Peer VPN
(dal sito ufficiale http://www.ntop.org/products/n2n/)

n2n is a layer-two peer-to-peer virtual private network (VPN) which allows users to exploit features typical of P2P applications at network instead of application level. This means that users can gain native IP visibility (e.g. two PCs belonging to the same n2n network can ping each other) and be reachable with the same network IP address regardless of the network where they currently belong. In a nutshell, as OpenVPN moved SSL from application (e.g. used to implement the https protocol) to network protocol, n2n moves P2P from application to network level.

The main n2n design features are:

  • An n2n is an encrypted layer two private network based on a P2P protocol.
  • Encryption is performed on edge nodes using open protocols with user-defined encryption keys: you control your security without delegating it to companies as it happens with Skype or Hamachi.
  • Each n2n user can simultaneously belong to multiple networks (a.k.a. communities).
  • Ability to cross NAT and firewalls in the reverse traffic direction (i.e. from outside to inside) so that n2n nodes are reachable even if running on a private network. Firewalls no longer are an obstacle to direct communications at IP level.
  • n2n networks are not meant to be self-contained, but it is possible to route traffic across n2n and non-n2n networks.

esempio:

configuro il mio server che farà da supernodo (ma pi puo’ anche far girare il client in se stesso) in modo da avere un ip e porta visibili sulla rete esterna Internet (generalmente configurando regole di natting sul modem)

supernode -l 8000

e supponiamo che il mio ip pubblico in questo momento sia 83.73.63.53 (consiglio di usare un server con ip fisso oppure un servizio di dyndns).

Su ogni client avvio il programma edge:

node1> edge -a 10.1.2.1 -c miarete -k miapassword -l 83.73.63.53:8000
node2> edge -a 10.1.2.2 -c miarete -k miapassword -l 83.73.63.53:8000
node3> edge -a 10.1.2.3 -c miarete -k miapassword -l 83.73.63.53:8000
..
node20> edge -a 10.1.2.20 -c miarete -k miapassword -l 83.73.63.53:8000

a questo punto tutti i client sono in grado di comunicare tra di loro alla massima velocità teorica (di ogni client).

Raffiniamo il supernodo in modo da loggare più informazioni:
supernode -l 7000 -v >> /var/log/n2n.log

E poi raffiniamo il comando del client, si può usare -b (risolve periodicamente il nome del server in ip, utile se si usa dyndns), -d per dare un nome alla nostra interfaccia di rete vpn

edge -a mioip -c miarete -k miapassword -l IPserver:PORTA -d n2n -b

-d <name> sets the TAP device name as seen in ifconfig. Only available on Linux.

-b cause edge to perform hostname resolution for the supernode address each time the supernode is periodically contacted. This can cause reliability problems because all packet processing stops while the supernode address is resolved which might take 15 seconds.

-K <keyfile> Reads a key-schedule file <keyfile> and populates the internal transform operations with the data found there. This mechanism allows keys to roll at pre- determined times for a group of hosts. Accurate time synchronisation is not required as older keys can be decoded for some time after expiry. If neither -k nor -K is used to specify a key source then edge uses cleartext mode (no encryption). The -k and -K options are mutually exclusive.

Infine consiglio di modificarsi il proprio file /etc/hosts e inserire i nomi dei pro
NB: viene utilizzato il protocollo UDP. Per tunnellizzare UDP sul TCP ci sono diversi modi..