ZeroTier One: Set up a self-hosted controller to create your own virtual network.

Nowadays it is useful to be able to bring together all the devices you own under a single virtual network, so that you can access them more easily and be able to control them even remotely, without necessarily exposing them to the rest of the world. There are various methods to create a VPN (Virtual Private Network) and, in principle, they are not really within everyone's reach. A few days ago, however, we ran into Niveau zéro, an open-source solution that allows anyone to create their own virtual network without having any specific skills, thanks to a very simple wizard and an application that guarantees a totally encrypted and authenticated connection through algorithms such as 256-bit Salsa20 and Poly1305.




The starting point is precisely to create the virtual network that will allow our devices to connect to each other as if they were connected to the same local area network (LAN). To do this you can use the Central controller hosted by ZeroTier at my.zerotier.com, a web-based UI portal for managing virtual networks. To register, simply provide your email and password and, once logged in, you can create your own virtual network, identified by a unique 16-digit ID.

La dernière étape consiste à installer le client ZeroTier sur chaque appareil que vous souhaitez connecter au réseau, avec l'abonnement gratuit pour une utilisation non commerciale, vous pouvez connecter jusqu'à 100 appareils au contrôleur de réseau ZeroTier Central. Pratiquement tous les systèmes populaires sont pris en charge, y compris les appareils mobiles Android et iOS et le micrologiciel de divers NAS tels que Sinology. Une fois l'application installée, chaque appareil sera à son tour identifié par un identifiant à 10 chiffres : indiquez simplement l'identification à 16 chiffres de votre réseau pour lancer la configuration automatique.


Configure a standalone network controller

Nous l'avons essayé et nous avons voulu aller plus loin en essayant de faire un premier pas vers une solution auto-hébergée, en configurant notre contrôleur qui n'est pas exposé publiquement. Dans cet article, nous verrons comment configurer votre propre contrôleur de réseau autonome sans forcément passer de l'inscription à my.zerotier.com.



La configuration d'un contrĂ´leur autonome est assez simple : il suffit d'installer le logiciel ZeroTier One and follow the installation instructions below to install ztncui sur une machine Linux.

Pré-requis

  • Machine Ubuntu avec 1 Go de RAM
  • ouvrir le port 9993 si un nĹ“ud cible est derrière un pare-feu (pas obligatoire mais diminue la latence)

L’installation

Let's connect to our Linux machine and start installing the client. Debian and RPM based distributions including Debian, Ubuntu, CentOS, RHEL, Fedora and others are supported via a script that adds the right repository and installs the package. The following command is also shown on the ZeroTier download page zerotier.com/download.shtml.

curl -s https://install.zerotier.com | sudo bash

At this point the Zerotier client will be installed on our machine, now let's add the repository to download Ztncui, i.e. what will be our controller.

curl -O https://s3-us-west-1.amazonaws.com/key-networks/deb/ztncui/1/x86_64/ztncui_0.5.8_amd64.deb

Installons-le avec la commande suivante :

sudo apt-get install ./ztncui_0.5.8_amd64.deb

Optional: once ztncui is installed we can install SSL certificates, by default auto-generated self-signed certificates will be used, but you can generate your own by filling them with your personal information using the following commands:


sudo -i

cd /opt/key-networks/ztncui/etc/tls

rm -f privkey.pem fullchain.pem

openssl req -x509 -sha256 -nodes -days 365 -newkey rsa:2048 -keyout privkey.pem -out fullchain.pem

chown ztncui.ztncui *.pem

chmod 600 privkey.pem

We restrict access to port 3443 on the public network interface to our own IP address (at least until the admin password is set).

sudo sh -c "echo 'HTTPS_PORT = 3443'> /opt/key-networks/ztncui/.env"


Having already got a certificate and private key, you should be able to access ztncui over HTTPS on the port specified by HTTPS_PORT.


At this point we can use our controller, let's connect via HTTPS on port 3443 via web browser, https: //: 3443

ZeroTier One: Set up a self-hosted controller to create your own virtual network.
I accessed as admin user with password password .
ZeroTier One: Set up a self-hosted controller to create your own virtual network.

Further users can then be created via the menu User>Create User en saisissant nom d'utilisateur, mot de passe et en précisant si le mot de passe sera modifié lors de la première connexion.

ZeroTier One: Set up a self-hosted controller to create your own virtual network.
Une fois cela fait, les nouveaux utilisateurs apparaîtront dans la liste (il est recommandé de supprimer le compte admin créé par défaut à l'aide de l'icône appropriée).
ZeroTier One: Set up a self-hosted controller to create your own virtual network.

Du menu Réseau il est possible de créer le réseau qui nous permettra de connecter tous les appareils distants. Nous cliquons sur Ajouter un réseau and choose a name for our network.


ZeroTier One: Set up a self-hosted controller to create your own virtual network.

Let's go back to the Home where it is possible to identify the 16-digit ID of the newly created virtual network. By clicking on List all networks on this controller il sera possible de configurer notre réseau.

Cliquez sur installation facile.

Nous avons la possibilité d'attribuer ou de générer automatiquement une classe IP pour le réseau virtuel et de définir la plage d'adresses qui seront utilisées par les appareils que nous ajoutons.

Une fois confirmé, nous revenons à la page précédente; en cliquant sur détails nous pourrons avoir plus d'informations sur le réseau nouvellement créé.

En cliquant sur membres we will be able to consult the list of added devices. Obviously the list will be empty.


Cependant, nous pouvons ajouter notre propre contrĂ´leur en tapant la commande sur notre terminal :

sudo zerotier-cli join [networkID]

OĂą [networkID] est le code Ă  16 chiffres qui identifie notre rĂ©seau. Vous pouvez vĂ©rifier l'Ă©tat de la connexion avec la commande :


statut sudo zerotier-cli

À ce stade, une erreur telle que "ACCESS_DENIED" est normale, car le client doit être activé. Passons donc à la rubrique Network>Members de notre contrôleur, l'ID de l'appareil nouvellement ajouté sera affiché auquel nous pouvons attribuer un nom afin de le reconnaître plus facilement. L'activation du drapeau autorisera l'appareil à faire partie de notre réseau, nous pouvons en effet voir qu'il s'est vu attribuer automatiquement une IP appartenant au pool précédemment défini (elle peut être modifiée si vous le souhaitez).

Pour ajouter les autres appareils à la place, nous pouvons toujours télécharger le client à partir de la page de téléchargement ZeroTier. Il sera possible de sélectionner l'icône correspondant au système d'exploitation de l'appareil que nous souhaitons ajouter au réseau.

For example, if we select Windows we will download the .msi package to be installed directly on the machine. We can also connect mobile devices through the Zerotier One app available on both the Play Store and the Apple Store. The procedure will be similar to the one explained above: install the client, join the network identified by the 16 digits and enable the added devices from the dashboard of our controller. The next image will show the different clients that we added during our test.

Désormais, nos appareils seront également accessibles à distance, depuis n'importe quelle destination en utilisant les adresses IP attribuées.

Routing between ZeroTier and physical networks

The fact of having to use IP addresses other than those of the office LAN to identify our company devices didn't excite us, it would have been more convenient to connect to the machines without having to remember all the virtual IPs assigned by the ZeroTier network. So, looking through the documentation we found a way to do it.

The steps to be performed are as follows:

  1. Install ZeroTier on a Linux machine qui servira de passerelle
  2. Ajouter une nouvelle route sur notre contrĂ´leur ZeroTier
  3. Activer le transfert IP
  4. je vais configurer iptables

This is a summary table containing the example parameters that we will need for the configuration, to be replaced with your configuration.

Info EXEMPLE Variable
ID réseau ZeroTier 865e7201263ef8e07 $NETWORK_ID
Name interface ZeroTier zt7nnig26 $ZT_IFACE
Nom de l'interface physique eth0 $PHY_IFACE
Subnet di ZeroTier 10.100.10.0/24
Bureau de physique du sous-réseau (cible) 192.168.1.0/24 $PHY_SUB
ZeroTier Gateway IP address 84.100.10.100 $ZT_ADDR

1.Install ZeroTier on a Linux machine qui servira de passerelle

Au sein du réseau LAN, il sera nécessaire de configurer une machine Ubuntu, d'installer le client ZeroTier et d'ajouter la machine au réseau virtuel en lui permettant d'obtenir une IP, comme indiqué ci-dessus.
Dans notre cas, le contrôleur lui-même fait partie du réseau physique, nous utiliserons donc cette même machine comme "routeur".

2.Add a managed route to the ZeroTier network on our controller

In this step we will add another route for any device connected to the ZeroTier network. Let's go to Réseau>détails comme indiqué ci-dessus, puis cliquez sur routes.

La page affichera la route existante actuelle, créée par défaut lors de la création du réseau virtuel. Nous allons en ajouter un nouveau en définissant comme cible la classe IP qui identifie notre réseau physique d'entreprise et comment Réseau the virtual IP address of the linux machine. It is recommended to configure the target class with a slightly larger subnet than the actual physical subnet, so that devices located on both the physical and virtual networks of ZeroTier still prefer the physical connection. In our example our internal lan is 192.168.1.0/24 so we will set 192.168.1.0/23 instead of /24 (a smaller number is a bigger subnet in this notation) while the virtual IP of the gateway, as well as our controller , is 84.100.10.100.

Cliquez sur Envoyez and the new route will be added to the list.

3.Activer le transfert IP

At this point let's connect to the Linux terminal and edit the file /etc/sysctl.conf en utilisant la commande

sudo you /etc/sysctl.conf

et décommentez la ligne pour net.ipv4.ip_forward suppression #. Nous sauvegardons et fermons le fichier en appuyant sur Esc et en tapant : wq! followed by the confirmation enter key.

Forwarding will be enabled at the next restart of the machine, to enable it immediately type the command:

sudo sysctl -w net.ipv4.ip_forward=1

4.Configure iptables

Also from the Ubuntu shell we assign two variables that will make subsequent commands easier for us. The values ​​assigned correspond to the 2 network interfaces of the machine, to display them key in i via shells; you will get something like eth0 and ztnnig26. We set the variables with the following command:

PHY_IFACE=eth0; ZT_IFACE=zt7nnig26

Let's add the rules to the ip tables:

sudo iptables -t nat -A POSTROUTING -o $PHY_IFACE -j MASQUERADE

sudo iptables -A FORWARD -i $PHY_IFACE -o $ZT_IFACE -m state --state RELATED,ESTABLISHED -j ACCEPT

sudo iptables -A AVANT -i $ZT_IFACE -o $PHY_IFACE -j ACCEPTER

Nous enregistrons également les règles pour le prochain démarrage

sudo apt install iptables-persistent sudo bash -c iptables-save > /etc/iptables/rules.v4

Les tests!

Il ne reste plus qu'Ă  tester la configuration ;

  • Connectez le PC Ă  un autre rĂ©seau (diffĂ©rent du LAN nouvellement ajoutĂ©)
  • Ajoutez-le au rĂ©seau zerotier et activez l'autorisation
  • Try to access some LAN network machine that you added earlier using the IP of the physical network

Conclusions

Obviously ZeroTier offers much more than what is described in this article, just consult the manual to realize its potential. Let's say that, after reading the manual, we decided to try to get a self-hosted solution by deciding to present this interesting product through a quick guide. We also had excellent impressions regarding the connection speed, comparable to that of our point-to-site VPN that we usually use.
Obviously what is shown in this article is only a first step towards having a completely independent infrastructure. At the moment, however, the 4 zerotier root servers located in different geographical areas are used to establish connections between the different peers. The current version of zerotier would allow you to create your own root servers but this feature is still considered somewhat experimental, so we decided to stop there for the moment given the imminent arrival of version 2.0. So we just have to wait for the arrival of the new version to find out if there will be interesting news.

NB For more critical situations, where, for example, confidential data or particular equipment is involved, it is better to focus on VPN solutions managed entirely in-house rather than third-party software. If you need to know the best solution for you, please contact us!

Liens utiles

https://www.zerotier.com/manual/

https://zerotier.atlassian.net/wiki/spaces/SD/overview

https://www.zerotier.com/2019/09/24/zerotier-2-0-status/

https://key-networks.com/ztncui/

ajouter un commentaire de ZeroTier One: Set up a self-hosted controller to create your own virtual network.
Commentaire envoyé avec succès ! Nous l'examinerons dans les prochaines heures.