« WireGuard LXC Alpine Linux » : différence entre les versions
Aller à la navigation
Aller à la recherche
| Ligne 49 : | Ligne 49 : | ||
lxcalpine:~# apk add wireguard-tools | lxcalpine:~# apk add wireguard-tools | ||
On | On récupère la configuration sur [https://www.wireguardconfig.com/ '''wireguardconfig'''] | ||
<code># vi /etc/wireguard/wg0.conf</code> | <code># vi /etc/wireguard/wg0.conf</code> | ||
Version du 15 mai 2021 à 21:02
100 % Testé et approuvé
ProxMox
Côté serveur.
proxmox:~# apt update && apt upgrade proxmox:~# apt install pve-headers
WireGuard n'est pas disponible sur la version actuelle de ProxMox/Debian, il faut donc soit passer par les dépots "backports" ou les dépôts "testing".
- Via Backport :
On active les dépots "backports" si ce n'est pas déjà fait :
proxmox:~# echo 'deb http://deb.debian.org/debian buster-backports main' >> /etc/apt/sources.list proxmox:~# apt update
On install et active le module WireGuard :
proxmox:~# apt install -t buster-backports wireguard-dkms proxmox:~# modprobe wireguard proxmox:~# echo "wireguard" >> /etc/modules-load.d/modules.conf
- Via les dépôts testing, on active les dépôts testing et on exécute les commandes suivantes :
proxmox:~# apt update proxmox:~# apt install wireguard-dkms proxmox:~# modprobe wireguard proxmox:~# echo "wireguard" >> /etc/modules-load.d/modules.conf
LXC Alpine 3.12
WireGuard Server
HDD : 0,5G / CPU : 1 / RAM : 256mb ??
Avec un téléphone android connecté !!! :
Côté conteneur LXC.
On autorise el routage :
lxcalpine:~# echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf lxcalpine:~# sysctl -p
net.ipv4.ip_forward = 1
lxcalpine:~# rc-update add sysctl default
Puis on install :
lxcalpine:~# apk update && apk upgrade lxcalpine:~# apk add wireguard-tools
On récupère la configuration sur wireguardconfig
# vi /etc/wireguard/wg0.conf
[Interface] Address = 10.0.0.1/24 ListenPort = 51820 PrivateKey = ***************************************** PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE [Peer] PublicKey = ***************************************** PresharedKey = ***************************************** AllowedIPs = 10.0.0.2/32 [Peer] PublicKey = ***************************************** PresharedKey = ***************************************** AllowedIPs = 10.0.0.3/32 [Peer] PublicKey = ***************************************** PresharedKey = ***************************************** AllowedIPs = 10.0.0.4/32
# vi /etc/wireguard/client1.conf
[Interface] Address = 10.0.0.2/24 ListenPort = 51820 PrivateKey = ***************************************** [Peer] PublicKey = ***************************************** PresharedKey = ***************************************** AllowedIPs = 0.0.0.0/1, 128.0.0.0/1 Endpoint = myserver.dyndns.org:51820
Test
lxcalpine:~# wg-quick up wg0
[#] ip link add wg0 type wireguard [#] wg setconf wg0 /dev/fd/63 [#] ip -4 address add 10.0.0.1/24 dev wg0 [#] ip link set mtu 1420 up dev wg0 [#] iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
lxcalpine:~# wg
interface: wg0 public key: ***************************************** private key: (hidden) listening port: 51820 peer: ***************************************** preshared key: (hidden) allowed ips: 10.0.0.2/32 peer: ***************************************** preshared key: (hidden) allowed ips: 10.0.0.3/32 peer: ***************************************** preshared key: (hidden) allowed ips: 10.0.0.4/32
Fin du test :
lxcalpine:~# wg-quick down wg0
[#] ip link delete dev wg0 [#] iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
wg0 au boot via init.d
lxcalpine# vi /etc/init.d/wireguard
#!/sbin/openrc-run
depend() {
need localmount
need net
}
start() {
ebegin "Starting wireguard"
/usr/bin/wg-quick up wg0
eend $?
}
stop() {
ebegin "Stopping wireguard"
/usr/bin/wg-quick down wg0
eend $?
}
lxcalpine# chmod +x /etc/init.d/wireguard
lxcalpine# rc-update add wireguard default
On lance :
lxcalpine# service wireguard start
On peut tester avec "wg", rebooter pour vérifier etc...
(Optionnel) QR Code
lxcalpine# apk add libqrencode
Exemple :
lxcalpine# qrencode -t ansiutf8 < /etc/wireguard/client1.conf
voila!