Here I post a full config to set up a Wireguard connection. It deals with DNS, changing IP's behind the DNS and is restart-proof.
Just adjust:
- `<YOURDNS>
- <server.pub>
- <preshared.psk>
- 192.168.150.0 if your wireguard server is a hop and LibreELEC needs to talk to a device within 192.168.150.0/24 behind the hop. If not needed, you can remove it.
wg0.conf:
Code
vi /storage/.config/wireguard/wg0.conf
[Interface]
ListenPort = 51820
PrivateKey = <client.key>
[Peer]
PublicKey = <server.pub>
PresharedKey = <preshared.psk>
AllowedIPs = 10.1.1.0/24,192.168.150.0/24
Endpoint = <YOURDNS>:51820
PersistentKeepalive = 25
Display More
system.d (restart proof):
Code
vi /storage/.config/system.d/wg0.service
[Unit]
Description=start wireguard interface
Requires=network-online.service
After=time-sync.target
Before=kodi.service
[Service]
Type=oneshot
RemainAfterExit=true
StandardOutput=journal
ExecStart=ip link add dev wg0 type wireguard
ExecStart=ip address add dev wg0 10.1.1.3/24
ExecStart=wg setconf wg0 /storage/.config/wireguard/wg0.conf
ExecStart=ip link set up dev wg0
ExecStart=ip route add 192.168.150.0/24 dev wg0 src 10.1.1.3
ExecStop=ip route del 192.168.150.0/24 dev wg0 src 10.1.1.3
ExecStop=ip link set down dev wg0
ExecStop=ip address del dev wg0 10.1.1.3/24
ExecStop=ip link del dev wg0
[Install]
WantedBy=multi-user.target
systemctl enable wg0.service
reboot
#troubleshooting
systemctl daemon-reload
systemctl restart wg0.service
systemctl stop wg0.service
systemctl start wg0.service
systemctl status wg0.service
Display More
Create script for restarting Wireguard if IP behind DNS has changed:
```
Code
cd /storage/.config/wireguard/
touch /storage/.config/wireguard/restartWireguardIfNewIP.sh
chmod +x /storage/.config/wireguard/restartWireguardIfNewIP.sh
vi /storage/.config/wireguard/restartWireguardIfNewIP.sh
#!/bin/bash
cip=$(wg show wg0 endpoints | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}")
echo "$cip"
digIP=$(getent hosts <YOURDNS> | awk '{ print $1 }')
echo "$digIP"
if [ "$digIP" != "$cip" ]
then
echo "IP's are different, restart wireguard"
systemctl restart wg0.service
else
echo "IP's are same, don't do anything"
fi
Display More
```
Create cronjob, running every 5 mins:
If you use SMB, it needs to start after wireguard tunnel has started:
Test everything:
```
I hope it helps someone. Credits to ninze