Mounting Samba Shares Between CentOS Servers

In operations you often run into this: two CentOS servers, one running the app and one holding data, or one doing collection and one doing archiving, and both need to share the same directory. One of the simplest solutions is Samba (the SMB protocol) sharing, then mounting the share locally with mount -t cifs. Below are the common scenarios and the matching mount commands.

Prerequisites: Confirm the cifs Tools

Before mounting, confirm mount.cifs is present:

# Check whether it's installed
which mount.cifs

# Install if missing (CentOS 7/8)
yum install cifs-utils -y

Missing cifs-utils is one of the most common causes of the error "mount: unknown filesystem type 'cifs'" — install this package first.

1. Mounting an Anonymous Samba Share

mount -t cifs //192.168.2.2/share /151.2_share -o guest
  • -o guest: access the share as an anonymous guest, no username or password;
  • //192.168.2.2/share: the remote share path, formatted as //server-IP/share-name;
  • /151.2_share: the local mount point, which must exist first (mkdir -p).

Anonymous mounts are fine for low-sensitivity data exchange inside a LAN; for production, prefer authenticated access.

2. Mounting an Authenticated Samba Share

mount -t cifs //192.168.2.2/share /151.2_share -o username=samba,password=samba,iocharset=utf-8
  • username / password: the account used to access the share;
  • iocharset=utf-8: keeps Chinese filenames readable; without it they may appear garbled.

A plaintext password on the command line stays in history. Fine for a quick test, but for long-term use prefer a credentials file:

# Create a credentials file with tight permissions
vi /root/.smbcredentials
# Contents:
#   username=samba
#   password=samba
chmod 600 /root/.smbcredentials

mount -t cifs //192.168.2.2/share /151.2_share -o credentials=/root/.smbcredentials,iocharset=utf-8

3. Auto-Mounting at Boot (fstab)

Edit /etc/fstab:

vi /etc/fstab

Add a line for anonymous access:

//192.168.151.2/share   /151.2_share            cifs    defaults,guest  0 0

For authenticated access, replace guest with credentials=/root/.smbcredentials:

//192.168.2.2/share     /151.2_share            cifs    defaults,credentials=/root/.smbcredentials,iocharset=utf-8  0 0

fstab is the recommended way to mount at boot, but note that the network may not be ready early in startup, which can fail the mount. If that happens, add the _netdev option so the system mounts only after the network is available.

4. Auto-Mounting at Boot via rc.local

You can also put the mount command into /etc/rc.local:

chmod +x /etc/rc.local
vi /etc/rc.local

Add (replace the password with yours):

mount -t cifs -o username=root,password='your-password' //192.168.1.101/mnt/test/ /home/ceshi

rc.local runs late in the boot sequence, which naturally sidesteps the "network not ready" problem, though it's less maintainable than fstab.

5. Mounting with a Specific SMB Version

Older SMB servers (SMB1 only) and newer Windows systems with SMB1 disabled by default can both cause mount failures. In that case, explicitly specify the protocol version:

mount -t cifs -o vers=1.0,username=www,password=password //10.10.10.2/web /www/source

Common version values: vers=1.0, vers=2.0, vers=3.0. Which one to use depends on what the server supports. CentOS 7 and later default to higher SMB versions, so cross-version interop is the classic "I can ping it but the mount fails" case — try vers=3.0 first, then step down to debug.

6. Verification and Troubleshooting

After mounting, confirm with:

df -h | grep 151.2_share
mount | grep cifs

A quick error reference:

Error Signature Likely Cause Fix
unknown filesystem type 'cifs' Missing cifs-utils Install cifs-utils
mount error(13): Permission denied Auth failed / anonymous not allowed Check credentials or change auth method
mount error(112): Host is down Network down or port 445 blocked Check firewall and security group
Garbled Chinese filenames Missing iocharset Add iocharset=utf-8

Summary

  • Anonymous share: use -o guest;
  • Authenticated share: use -o username=xxx,password=xxx, add iocharset=utf-8, and prefer a credentials file long-term;
  • Auto-mount at boot: write to /etc/fstab (recommended, add _netdev) or /etc/rc.local;
  • Version mismatch: specify the SMB protocol with -o vers=1.0/2.0/3.0.

The steps above cover the client side. To set up a Samba server on CentOS and share directories with other machines, refer to CentOS 7 Samba share configuration. For more server configuration and operations content, see the cloud servers category, such as server operations tips.

Reference: Samba official docs https://www.samba.org/samba/docs/current/man-html/mount.cifs.8.html, Linux mount.cifs manual https://linux.die.net/man/8/mount.cifs
Original post: https://www.cnblogs.com/cqzhuomi/articles/17284369.html (cnblogs.com CQZHUOMI, repost)