Many Linux administrators encounter the frustrating scenario where Windows SMB shares mounted on Linux servers periodically disconnect with the cryptic error:
kernel: CIFS VFS: BAD_NETWORK_NAME: \\\\servername\\folder
This typically happens with configurations like:
//servername/folder /localfolder cifs credentials=/login.txt,x-systemd.automount,
x-systemd.device-timeout=5,_netdev,noserverino,noperm,sec=ntlmssp,vers=3.0 0 0
The x-systemd.automount option doesn't always handle SMB reconnections perfectly. Here are more robust alternatives:
//servername/folder /localfolder cifs credentials=/login.txt,_netdev,auto,
soft,timeo=30,retrans=3,noserverino,noperm,sec=ntlmssp,vers=3.0 0 0
Key improvements:
- soft mount instead of hard mount
- Explicit timeo and retrans values
- Removed problematic systemd options
Create /usr/local/bin/check_mount.sh:
#!/bin/bash
MOUNT_POINT="/localfolder"
SHARE="//servername/folder"
if ! mountpoint -q "$MOUNT_POINT"; then
logger "CIFS mount not present, attempting remount"
mount $MOUNT_POINT
if [ $? -ne 0 ]; then
umount -l $MOUNT_POINT
mount $MOUNT_POINT
fi
fi
Add to cron (crontab -e):
*/5 * * * * /usr/local/bin/check_mount.sh
For more stable connections, try these additional options:
vers=3.1.1,cache=strict,rsize=65536,wsize=65536,actimeo=30
Explanation of critical parameters:
- cache=strict: Better caching behavior
- rsize/wsize: Optimized for modern networks
- actimeo: Reduced attribute cache timeout
Install debugging tools:
sudo apt install cifs-utils
Check connection status:
sudo smbstatus
Enable detailed logging:
echo 7 > /proc/fs/cifs/cifsFYI
View logs:
dmesg | grep CIFS
Many Linux administrators encounter unstable CIFS mounts when connecting to Windows SMB shares. The BAD_NETWORK_NAME
error typically indicates one of several potential issues:
- Network connectivity interruptions
- Server-side share configuration changes
- Authentication token expiration
- Incomplete mount options
Your current fstab entry:
//servername/folder /localfolder cifs credentials=/login.txt,x-systemd.automount,
x-systemd.device-timeout=5,_netdev,noserverino,noperm,sec=ntlmssp,vers=3.0 0 0
While generally correct, let's enhance this configuration for better resilience:
Consider these additional parameters:
//fileserver/shared /mnt/share cifs credentials=/etc/cifs.creds,uid=1000,gid=1000,
file_mode=0770,dir_mode=0770,vers=3.1.1,_netdev,nofail,hard,rsize=65536,
wsize=65536,cache=none,user_xattr,noserverino,sec=ntlmssp 0 0
Key improvements:
- nofail: Prevents boot failures
- hard: Persistent retries on failures
- vers=3.1.1: Explicit SMB version
- cache=none: Reduces caching issues
Create a monitoring script (/usr/local/bin/check_cifs.sh
):
#!/bin/bash
MOUNT_POINT="/mnt/share"
SERVER="fileserver"
if ! mountpoint -q "$MOUNT_POINT"; then
logger "CIFS mount not present, attempting remount"
umount -l "$MOUNT_POINT" 2>/dev/null
mount "$MOUNT_POINT" && logger "CIFS remount successful"
fi
# Verify actual connectivity
if timeout 5 smbclient -U user //$SERVER/shared -c "ls" &>/dev/null; then
if ! timeout 5 ls "$MOUNT_POINT" &>/dev/null; then
logger "CIFS stale mount detected, forcing remount"
umount -l "$MOUNT_POINT"
mount "$MOUNT_POINT"
fi
fi
Create /etc/systemd/system/cifs-monitor.service
:
[Unit]
Description=CIFS Mount Monitor
After=network.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/check_cifs.sh
And a timer unit /etc/systemd/system/cifs-monitor.timer
:
[Unit]
Description=Run CIFS mount check every 5 minutes
[Timer]
OnBootSec=5min
OnUnitActiveSec=5min
[Install]
WantedBy=timers.target
When issues occur, collect these diagnostics:
# Check current SMB connections
sudo smbstatus
# View detailed CIFS debugging
echo 7 | sudo tee /proc/fs/cifs/cifsFYI
# Network connectivity test
sudo smbclient -L //servername -U username -d3