> ## Content Index
> Fetch the complete content index at: https://blog.lange-it.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# WireGuard | CIFS mount in Abhängigkeit zu WireGuard
- URL: https://blog.lange-it.com/wireguard-cifs-mount-in-abhangigkeit-zu-wireguard/
- Published: 2025-10-28T08:26:49.000Z
- Updated: 2025-10-28T08:33:13.000Z
- Author: Peter Lange
- Tags: WireGuard, Monitoring, cifs, Samba, systemd

# CIFS-Mount automatisch wiederverbinden, wenn WireGuard-Tunnel neu aufgebaut wird

Wenn ein CIFS-(SMB)-Mount von einem WireGuard-Tunnel abhängt, sollte der Mount beim Neuaufbau des Tunnels automatisch neu verbunden werden.  
Hier sind bewährte Varianten für Linux (systemd-basiert).

---

## 1\. Systemd-Mount-Unit mit Abhängigkeit zu WireGuard

**Beispiel:** `/etc/systemd/system/mnt-share.mount`

```ini
[Unit]
Description=CIFS Share
After=wg-quick@wg0.service
Requires=wg-quick@wg0.service

[Mount]
What=//server.example.local/share
Where=/mnt/share
Type=cifs
Options=credentials=/root/.smbcred,vers=3.0,iocharset=utf8,uid=1000,gid=1000

[Install]
WantedBy=multi-user.target

```

**Aktivieren:**

```bash
systemctl daemon-reload
systemctl enable mnt-share.mount

```

Sobald `wg-quick@wg0` neu gestartet wird, wird der Mount automatisch neu eingehängt.

---

## 2\. ExecUp/Down in der WireGuard-Konfiguration

In `/etc/wireguard/wg0.conf`:

```ini
[Interface]
PrivateKey = ...
Address    = 10.0.0.2/24
PostUp     = mount -a -t cifs
PostDown   = umount -a -t cifs

```

- `PostUp` läuft jedes Mal, wenn `wg-quick up wg0` ausgeführt wird – perfekt für ein erneutes Mounten.
- Verwende in `/etc/fstab` den Eintrag mit `noauto` (und ggf. `x-systemd.automount`).

---

## 3\. systemd.automount (empfohlen bei instabilen Verbindungen)

In `/etc/fstab`:

```
# //server/share  /mnt/share  cifs  credentials=/root/.smbcred,_netdev,x-systemd.automount,x-systemd.requires=wg-quick@wg0.service  0  0

```

- `x-systemd.automount`: Mount erst, wenn auf `/mnt/share` zugegriffen wird.
- `x-systemd.requires=wg-quick@wg0.service`: Stellt sicher, dass der Tunnel steht.

Das ist besonders robust, da systemd automatisch neu mountet, sobald wieder darauf zugegriffen wird.

---

## Zusätzliche Tipps

- Verwende sinnvolle CIFS-Optionen, z. B.:  
```  
soft,vers=3.0,iocharset=utf8,cache=strict,actimeo=30  
```
- Prüfe ggf. `NetworkManager-wait-online.service` oder `systemd-networkd-wait-online.service`, um Race Conditions beim Boot zu vermeiden.

---

**Kurzfassung:**  
Die eleganteste Lösung ist ein systemd-Mount mit `After=wg-quick@wg0.service` **oder** ein `x-systemd.automount`\-Eintrag in `/etc/fstab`.  
So wird der CIFS-Share automatisch neu verbunden, sobald der WireGuard-Tunnel (`wg-quick`) sich erneut verbindet.