Skip to main content

2 - Via l'utilisation du package Linux

Via l'utilisation du package Wireguard

Linux

1/ Tout d'abord vous devez installer wireguard sur la machine :

sudo apt-get install wireguard

Puis se déplacer dans le répertoire de wireguard, par défaut le dossier est vide : 

root@linux: cd /etc/wireguard/
root@linux: ls -al
total 28
drwx------   2 root root  4096 juin  13 12:03 ./
drwxr-xr-x 166 root root 12288 juin  13 11:24 ../

2/ Maintenant nous allons générer la clé privé et la clé publique :

wg genkey | tee privatekey | wg pubkey | tee publickey

Nous avons maintenant 2 fichiers dans le dossier wireguard : 

root@linux: wg genkey | tee privatekey | wg pubkey | tee publickey
WKtF71pM6wObswaXkbxJgwPhk8a6lqrPb9oKFjaGOmM=
root@linux: ls -al
total 28
drwx------   2 root root  4096 juin  14 15:55 .
drwxr-xr-x 166 root root 12288 juin  13 11:24 ..
-rw-r--r--   1 root root    45 juin  14 15:55 privatekey
-rw-r--r--   1 root root    45 juin  14 15:55 publickey

3/ Pour continuer la configuration il faut noter le contenu des 2 clés générés : 

root@linux: cat privatekey 
iApdu05JqNGSp/r7PSpJ5Zqxs4kWSR6qYv9onitvsmo=

root@linux: cat publickey 
WKtF71pM6wObswaXkbxJgwPhk8a6lqrPb9oKFjaGOmM=

Attention ne partagez jamais votre clé privé !!

Clé privé : iApdu05JqNGSp/r7PSpJ5Zqxs4kWSR6qYv9onitvsmo=
Clé publique : WKtF71pM6wObswaXkbxJgwPhk8a6lqrPb9oKFjaGOmM=

4/a) Création du fichier de configuration Wireguard client :

touch wg0.conf

4/b)  Préparer dans un bloc note la configuration suivante :

Il faut bien veiller à remplacer les variables :

  • <private_key_client> -> Clé privé généré précédemment 
  • <range_ip_vpn>              -> Adresse IP VPN du client
  • <public_key_server>   -> Clé publique du serveur (A récupérer sur le serveur)
  • <ip_server>                     -> Adresse IP du serveur
  • <port_server>                -> Port écoutant sur le serveur
[Interface]
PrivateKey = <private_key_client>
Address = <range_ip_vpn>

[Peer]
###Public of the WireGuard VPN Server
PublicKey = <public_key_server>

### IP and Port of the WireGuard VPN Server
Endpoint = <ip_server>:<port_server>

### Allow all traffic
AllowedIPs = 0.0.0.0/0

4/c) Editer le fichier de configuration en collant la configuration complété :

nano wg0.conf
# ou
vim wg0.conf

Ce qui donne : 

[Interface]
PrivateKey = iApdu05JqNGSp/r7PSpJ5Zqxs4kWSR6qYv9onitvsmo=
Address = 192.168.10.15/24

[Peer]
###Public of the WireGuard VPN Server
PublicKey = <public_key_server>

### IP and Port of the WireGuard VPN Server
Endpoint = vpn.domaine-name.com:51820

### Allow all traffic
AllowedIPs = 0.0.0.0/0


Le reste de la configuration continue sur la partie serveur

Sur le serveur Wireguard

Préparer la commande suivante :

wg set wg0 peer <public_key_client> allowed-ips <adress_ip_vpn_client>

Ce qui donne : 

wg set wg0 peer WKtF71pM6wObswaXkbxJgwPhk8a6lqrPb9oKFjaGOmM= allowed-ips 192.168.10.15

Puis exécuter la commande.

Pour être sur du bon fonctionnement de la commande précédente, nous pouvons lister les clients enregistré dans le fichier de conf du serveur : 

wg show wg0

Maintenant il faut confirmer et enregistrer la modification du fichier de configuration : 

wg-quick save wg0