« WireGuard LXC Alpine Linux » : différence entre les versions

De Le Wiki de Lug
Aller à la navigation Aller à la recherche
Ligne 36 : Ligne 36 :


On autorise el routage :
On autorise el routage :
  # echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf
  lxcalpine:~# echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf
  # sysctl -p
  lxcalpine# sysctl -p


  net.ipv4.ip_forward = 1
  net.ipv4.ip_forward = 1


  # rc-update add sysctl default
  lxcalpine# rc-update add sysctl default


Puis on install :
Puis on install :


  # apk update && apk upgrade
  lxcalpine# apk update && apk upgrade
  # apk add wireguard-tools
  lxcalpine# apk add wireguard-tools


On récup la configuration sur [https://www.wireguardconfig.com/ '''wireguardconfig''']
On récup la configuration sur [https://www.wireguardconfig.com/ '''wireguardconfig''']
Ligne 100 : Ligne 100 :
  [#] iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
  [#] iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE


  # wg
  lxcalpine# wg


  <font color=green>interface: wg0</font>
  <font color=green>interface: wg0</font>
Ligne 120 : Ligne 120 :


Fin du test :
Fin du test :
  # wg-quick down wg0
  lxcalpine# wg-quick down wg0


  [#] ip link delete dev wg0
  [#] ip link delete dev wg0
Ligne 129 : Ligne 129 :
[https://gist.github.com/r0v/48e18c9584d4b5ecb96f593dec9a938c '''source''']
[https://gist.github.com/r0v/48e18c9584d4b5ecb96f593dec9a938c '''source''']


  # vi /etc/init.d/wireguard
  lxcalpine# vi /etc/init.d/wireguard


  #!/sbin/openrc-run
  #!/sbin/openrc-run
Ligne 150 : Ligne 150 :
  }
  }


  # chmod +x /etc/init.d/wireguard
  lxcalpine# chmod +x /etc/init.d/wireguard


  # rc-update add wireguard default
  lxcalpine# rc-update add wireguard default


On lance :
On lance :
  # service wireguard start
  lxcalpine# service wireguard start
On peut [[#Test|tester]] avec "wg", rebooter pour vérifier etc...
On peut [[#Test|tester]] avec "wg", rebooter pour vérifier etc...


== (Optionnel) QR Code ==
== (Optionnel) QR Code ==


  # apk add libqrencode
  lxcalpine# apk add libqrencode


Exemple :
Exemple :
  # qrencode -t ansiutf8 < /etc/wireguard/client1.conf
  lxcalpine# qrencode -t ansiutf8 < /etc/wireguard/client1.conf


voila!
voila!

Version du 15 mai 2021 à 20:57

100 % Testé et approuvé

   

ProxMox

source

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

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é !!! :

Incroyablement économe !


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 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

# 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

source

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!