Lab 5: Configure Persistent Network Mount (SMB/CIFS) at Boot

Configure a remote SMB/CIFS network share to mount automatically at boot using /etc/fstab.

← Back to Lab Main

Prerequisites

Step 1: Install Required Package

sudo apt update
sudo apt install cifs-utils -y

Step 2: Verify Network Connectivity

ping <server_ip>

Ensure the remote server is reachable before proceeding.

Step 3: Create the Local Mount Point

sudo mkdir -p /mnt/fileshare

The mount point must exist before mounting.

Step 4: Test Manual Mount (Temporary)

sudo mount -t cifs //<server_ip>/<share_name> /mnt/fileshare \
-o username=<username>,password=<password>,vers=3.0

If successful, verify:

lsblk
df -h
ls /mnt/fileshare

Unmount after testing:

sudo umount /mnt/fileshare

Step 5: Secure Credentials (Recommended)

sudo nano /root/.smbcredentials

Add:

username=<username>
password=<password>

Secure the file:

sudo chmod 600 /root/.smbcredentials

Step 6: Add Entry to /etc/fstab

sudo nano /etc/fstab

Add the following line (replace placeholders):

//<server_ip>/<share_name>  /mnt/fileshare  cifs  credentials=/root/.smbcredentials,vers=3.0,_netdev  0  0

Explanation:

Step 7: Validate fstab Configuration

sudo mount -a

If no errors are returned, the configuration is valid.

Step 8: Reboot and Confirm Persistent Mount

sudo reboot

After reboot, verify:

df -h
ls /mnt/fileshare

Confirm the share is mounted automatically and accessible.