omv8:omv8_plugins:wireguard

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
omv8:omv8_plugins:wireguard [2025/12/27 19:03] – [If the client is a PC (Linux, macOS, or Windows)] chenteomv8:omv8_plugins:wireguard [2025/12/31 08:57] (current) – [Update DuckDNS IP, receive notifications only when it changes, and restart the tunnel if needed] chente
Line 309: Line 309:
   * In OMV, go to **Services** > **Wireguard** > **Clients** and click **Client Config**.     * In OMV, go to **Services** > **Wireguard** > **Clients** and click **Client Config**.  
     * Copy the configuration text into a file and save it with the ''.conf'' extension on the PC.     * Copy the configuration text into a file and save it with the ''.conf'' extension on the PC.
-  * Open the Wireguard app on the PC and choose **Add connection from file**. Select the saved `.conffile and click **OK**.  +  * Open the Wireguard app on the PC and choose **Add connection from file**. Select the saved ''.conf'' file and click **OK**.  
     * If this option is not available, create a new connection and paste the configuration manually.     * If this option is not available, create a new connection and paste the configuration manually.
   * The client is now configured. Activate the connection to access your server network.   * The client is now configured. Activate the connection to access your server network.
Line 555: Line 555:
  
  
-=== Update DuckDNS IP, receive notifications only when it changes, and restart WireGuard automatically ===+=== Update DuckDNS IP, receive notifications only when it changes, and restart the tunnel if needed ===
  
-You can add this script to scheduled task so that your public IP is updated, and you receive a notification only if it changes.+This script can be added to an OMV scheduled task. It will: 
 +  * Update your DuckDNS IP if it has changed. 
 +  * Reactivate the tunnel interface if it is down. 
 +  * Send an email only when changes occur.
  
-Additionally, if you are using a WireGuard tunnel between two servers and the public IP changes on one of themthe tunnel may drop connections (because it will still try to reach the old IP)Restarting the service automatically allows the peer to establish a new //handshake//updating the tunnel with the new IP.+Useful for securing persistent connections between servers, e.g., for backups.
  
-  Example command:+**WireGuard tunnel naming in OMV-extras plugin**
  
-<html><body><pre><code>curl -s -k "https://www.duckdns.org/update?domains=[MY_DOMAIN]&token=[MY_TOKEN]&ip=&verbose=true" | grep -q UPDATED && echo "UPDATED PUBLIC IP IN DUCKDNS" && systemctl restart wg-quick@wgnet[MY_TUNNEL]</code></pre></body></html>+  * Standard tunnels: 
 +    * Tunnel number 1 → ''wgnet1'' 
 +    * Tunnel number 2 → ''wgnet2'' … 
 +  * Custom tunnels: 
 +    * The plugin automatically prefixes the name with ''wgnet_''. 
 +      * Example: if you name your custom tunnel ''pp'', its internal name will be ''wgnet_pp''
 +      * Example: if you name it ''backup'', its internal name will be ''wgnet_backup''.
  
-  Replace ''[MY_DOMAIN]'' and ''[MY_TOKEN]'' with your values.   +Summary: 
-  * Replace ''[MY_TUNNEL]'' with your WireGuard tunnel name.   +  Standard: ''wgnet1''''wgnet2''  
-    * For custom tunnelsadd an underscore: ''wgnet_[MY_TUNNEL]''.   +  * Custom: ''wgnet_<your_custom_name>'' 
-  * Enable OMV notifications to get an alert if the public IP changes.  + 
 +Important: The TUNNELS variable in the scheduled task script must use these internal names to correctly check and reactivate the interfaces. 
 + 
 +**Script example:** 
 + 
 +<html><body><pre><code> 
 +DOMAIN="[MY_DOMAIN]" 
 +TOKEN="[MY_TOKEN]" 
 +TUNNELS="wgnet1 wgnet2 wgnet_backup" 
 +UPDATED=0 
 + 
 +# Update IP address in DuckDNS 
 +curl -s -k "https://www.duckdns.org/update?domains=${DOMAIN}&token=${TOKEN}&ip=&verbose=true" | grep -q UPDATED && { 
 +    echo "IP updated in DuckDNS" 
 +    UPDATED=1 
 +
 + 
 +# Check tunnel status and reactivate if needed 
 +for TUNNEL in $TUNNELS; do 
 +    ip link show "$TUNNEL" >/dev/null 2>&1 || { 
 +        echo "WireGuard $TUNNEL down, reactivating..." 
 +        systemctl start wg-quick@"$TUNNEL" || exit 1 
 +        UPDATED=1 
 +    } 
 +done 
 + 
 +[ "$UPDATED" -eq 1 ] && echo "CHANGES APPLIED" || true 
 +</code></pre></body></html> 
 + 
 +**How to use:** 
 +  * Replace placeholders with your real values: 
 +    * [MY_DOMAIN] = Your DuckDNS domain (without .duckdns.org) 
 +    * [MY_TOKEN] = Your DuckDNS token 
 +    * [MY_TUNNEL_NUMBER_1], [MY_TUNNEL_NUMBER_2], etc= Internal tunnel names as described above 
 +  * Single-line version for OMV Scheduled Tasks: 
 +    * <html><body><pre><code>DOMAIN="[MY_DOMAIN]"; TOKEN="[MY_TOKEN]"; TUNNELS="wgnet1 wgnet_backup"; UPDATED=0; curl -s -k "https://www.duckdns.org/update?domains=${DOMAIN}&token=${TOKEN}&ip=&verbose=true" | grep -q UPDATED && { echo "IP updated in DuckDNS"; UPDATED=1; }; for TUNNEL in $TUNNELS; do ip link show "$TUNNEL" >/dev/null 2>&1 || { echo "WireGuard $TUNNEL down, reactivating..."; systemctl start wg-quick@"$TUNNEL" || exit 1; UPDATED=1; }; done; [ "$UPDATED" -eq 1 ] && echo "CHANGES APPLIED" || true</code></pre></body></html> 
 +  * Enable OMV notifications to receive alerts when the public IP changes or a tunnel is reactivated.
   * Add a descriptive label to your scheduled task.   * Add a descriptive label to your scheduled task.
-  * Once configured, just copy the command into **Scheduled Tasks** and set the execution interval.   +  * Make sure **curl** is installed before running the task.
-  * Remember to have **curl** installed before running the task.+
  
 ---- ----
  • omv8/omv8_plugins/wireguard.1766862206.txt.gz
  • Last modified: 2025/12/27 19:03
  • by chente