Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Storage Management: NFS and Samba

Introduction

In this tutorial, we will explore two popular file-sharing solutions in Linux: NFS (Network File System) and Samba. Both NFS and Samba allow you to share files between different systems, but they are used in different scenarios and have different configurations. We will cover the installation, configuration, and usage of both NFS and Samba.

NFS (Network File System)

1. Installing NFS

To install NFS on a Linux system, use the following commands:

sudo apt update

sudo apt install nfs-kernel-server

2. Configuring NFS

To configure NFS, you need to edit the /etc/exports file to specify the directories you want to share and the permissions. For example:

/srv/nfs 192.168.1.0/24(rw,sync,no_subtree_check)

This configuration shares the /srv/nfs directory with the network 192.168.1.0/24 and grants read-write access.

3. Starting the NFS Server

After configuring NFS, you can start the NFS server using the following commands:

sudo systemctl restart nfs-kernel-server

sudo systemctl enable nfs-kernel-server

4. Mounting NFS on Client

On the client machine, you need to install the NFS client package:

sudo apt install nfs-common

Then, create a mount point and mount the NFS share:

sudo mkdir -p /mnt/nfs

sudo mount 192.168.1.100:/srv/nfs /mnt/nfs

Replace 192.168.1.100 with the IP address of your NFS server.

Samba

1. Installing Samba

To install Samba on a Linux system, use the following commands:

sudo apt update

sudo apt install samba

2. Configuring Samba

To configure Samba, edit the /etc/samba/smb.conf file. Add a new share definition at the end of the file:

[shared]

path = /srv/samba

browseable = yes

writable = yes

This configuration shares the /srv/samba directory and allows it to be browsed and written to.3. Creating Samba User

To access the Samba share, you need to create a Samba user:

sudo smbpasswd -a username

Replace username with the actual username you want to add.

4. Starting the Samba Server

After configuring Samba, you can start the Samba server using the following commands:

sudo systemctl restart smbd

sudo systemctl enable smbd

5. Accessing Samba Share

On a Windows client, you can access the Samba share by opening the File Explorer and entering the following in the address bar:

\\192.168.1.100\shared

Replace 192.168.1.100 with the IP address of your Samba server and shared with the name of your share.

Conclusion

In this tutorial, we covered the installation and configuration of NFS and Samba for file sharing in Linux environments. While NFS is generally used for Unix-to-Unix sharing, Samba is commonly used for cross-platform sharing between Unix/Linux and Windows systems. Both solutions provide robust mechanisms for network file sharing.