- Posted on
- • Filesystem
Mounting Network Filesystems (NFS, SMB) in Linux
- Author
- 
                        - 
								
                                
                                - User
- Linux Bash
- Posts by this author
- Posts by this author
 
 
- 
								
                                
                                
Introduction: In the vast world of Linux, the ability to share and manage data over a network is crucial, especially in environments where files need to be accessed by multiple users or systems. This capability is predominantly achieved through network filesystems such as NFS (Network File System) and SMB (Server Message Block). This blog will guide you through the essentials of mounting these network file systems on your Linux machine, providing both a strong foundation for beginners and a useful refresher for experienced users.
What is NFS? Network File System (NFS) is a protocol that allows you to share files over a network. Developed by Sun Microsystems in the 1980s, NFS operates in a client-server environment where the server configures the files to be shared, and the client mounts the share to access the files. NFS uses a model that allows users to view and store files on a remote computer as if they were local to the user's own computer.
Setting Up NFS:
1. Install NFS Packages:
   - On a Debian/Ubuntu system, use: sudo apt install nfs-kernel-server nfs-common
   - On CentOS/RHEL, use: sudo yum install nfs-utils
   - On openSUSE, use: sudo zypper install nfs-kernel-server nfs-client
- Configure NFS Exports: - Create or select a directory to share, for example, /var/nfsshare.
- Edit the /etc/exportsfile to add this directory:/var/nfsshare <client_IP>(rw,sync,no_root_squash)
- Here, rwallows read/write access,syncrequires changes to be written to disk before they are applied, andno_root_squashlets the root user on the client have root privileges on the NFS volume.
 
- Create or select a directory to share, for example, 
- Export the Shares: - Run sudo exportfs -ato make the changes take effect.
 
- Run 
- Start and Enable NFS Service: - Use sudo systemctl start nfs-serverandsudo systemctl enable nfs-server.
 
- Use 
- Mounting on the Client: - Install NFS common files: sudo apt install nfs-common(Debian/Ubuntu) orsudo yum install nfs-utils(CentOS/RHEL) orsudo zypper install nfs-client(openSUSE).
- Create a mount point, e.g., mkdir /mnt/nfs.
- Add the mount to the client’s ‘/etc/fstab’ for persistent mounting:
<server_ip>:/var/nfsshare /mnt/nfs nfs defaults 0 0
- Mount the filesystem: sudo mount -a
 
- Install NFS common files: 
What is SMB? Server Message Block (SMB), also known as CIFS (Common Internet File System), is another network file sharing protocol used predominantly by Microsoft Windows systems. SMB allows computers to read and write to files and request services from server programs in a computer network.
Setting Up SMB:
1. Install Samba:
   - On Debian/Ubuntu, use: sudo apt install samba
   - On CentOS/RHEL, use: sudo yum install samba
   - On openSUSE, use: sudo zypper install samba
- Configure Samba Share: - Edit the /etc/samba/smb.conffile to configure the shared directory:[ShareName] path = /srv/samba/share available = yes valid users = @smbgroup read only = no browsable = yes public = yes writable = yes
 
- Edit the 
- Add Users and Set Permissions: - Create a group smbgroupand add users to it.
- Set appropriate permissions on the share directory.
 
- Create a group 
- Restart Samba Services: - sudo systemctl restart smbd.service nmbd.service
 
- Mounting SMB Share on a Linux Client: - Install client utilities: sudo apt install cifs-utils(Debian/Ubuntu) orsudo yum install cifs-utils(CentOS/RHEL) orsudo zypper install cifs-utils(openSUSE).
- Create a mount point: mkdir /mnt/smb
- Add to /etc/fstab://server_ip/ShareName /mnt/smb cifs username=smbuser,password=smbpass,iocharset=utf8 0 0
- Run sudo mount -a
 
- Install client utilities: 
Conclusion: Successfully mounting NFS and SMB shares in Linux can vastly improve the efficiency of file handling across networks in a home or corporate environment. By following these steps, you ensure that your networked systems are not only harmonized but are also secure and perform optimally. Whether you are deploying a multi-user system, a home server, or an enterprise network, mastering NFS and SMB is an essential skill for any Linux user.
Remember: Always consider security implications, particularly when allowing connections over the internet to your NFS or SMB shares. Use firewalls, secure passwords, and encrypted connections whenever possible.
Further Reading
For further reading on mounting NFS and SMB network filesystems in Linux, consider these resources:
- Understanding NFS: An article by Linode that goes into depth on configurations and options with NFS in Linux environments: Understanding NFS 
- Comprehensive Guide to Samba Setup on Linux: How to get SMB up and running on various Linux distributions with detailed examples: Samba Setup Guide 
- Securing NFS and SMB: This guide provides insights into securing NFS and SMB shares to prevent unauthorized access: Securing Network File Systems 
- Performance Tuning for NFS: Details on improving performance for NFS networking including benchmarks and parameters: Performance Tuning NFS 
- Advanced SMB Features: Explore advanced configuration options, troubleshooting, and security practices for SMB on Linux systems: SMB Advanced Features 
These articles should provide thorough insight and practical guidance for working with NFS and SMB in Linux, enhancing both your understanding and operational skills.