BCE-C712 Linux System Administration

0 of 74 lessons complete (0%)

Network Information System (NIS) and Network File System (NFS)

Preparing NFS

You don’t have access to this lesson

Please register or sign in to access the course content.

NFS stands for Network File System. It is a distributed file system protocol that allows a user on a client computer to access files over a network as if they were on the local file system. NFS is commonly used in Unix and Linux environments for sharing files and resources among multiple computers.

The NFS protocol allows a client system to mount (i.e., make accessible) a directory on a remote server as if it were a local directory. This enables users and programs to interact with files on a remote server as if they were stored locally.

NFS operates on the client-server model, where one or more servers provide access to their file systems, and multiple clients can access those file systems over the network. It is commonly used in situations where multiple computers need to share files and resources, such as in corporate networks or in cloud computing environments.

Keep in mind that while NFS is widely used, there are other file sharing protocols and systems available, like SMB/CIFS (used predominantly in Windows environments) and various cloud-based storage solutions. Each has its own strengths and may be more suitable for specific use cases.

Setting Up

Setting up NFS (Network File System) involves configuring a server to share directories and making them accessible to client systems over a network. NFS allows for easy file sharing and collaboration among multiple systems. Here’s a step-by-step guide to preparing NFS:

Step 1: Install NFS Packages

Ensure that the NFS server packages are installed on your system. The package names may vary depending on your Linux distribution:

# On Debian/Ubuntu sudo apt-get install nfs-kernel-server # On Red Hat/CentOS sudo yum install nfs-utils

Step 2: Create Directories to Share

Create the directories you want to share with other systems. For example, let’s create a directory named /shared:

sudo mkdir /shared

Step 3: Configure NFS Exports

Edit the NFS exports configuration file /etc/exports to specify which directories you want to share and which client systems are allowed to access them. Add a line like this:

/shared client_IP(rw,sync,no_root_squash)

Replace client_IP with the IP address or subnet of the client system(s) you want to allow access. The options rw allows read and write access, sync ensures synchronous writes, and no_root_squash allows the root user on the client to have root privileges on the shared files.

Step 4: Export the Directories

Apply the changes by exporting the directories:

sudo exportfs -a

Step 5: Start NFS Services

Start the NFS server services:

sudo service nfs-kernel-server start # On Debian/Ubuntu sudo systemctl start nfs-server # On Red Hat/CentOS (systemd)

Step 6: Set Up Firewall Rules (Optional)

If a firewall is enabled on your system, configure it to allow NFS traffic (TCP and UDP port 2049).

Step 7: Configure NFS Client (On Client Systems)

On the client system(s), you’ll need to mount the shared directory. Create a local mount point (e.g., /mnt/shared) and mount the NFS share:

sudo mkdir /mnt/shared sudo mount server_IP:/shared /mnt/shared

Replace server_IP with the IP address of the NFS server.

Step 8: Automounting (Optional)

To automatically mount NFS shares on the client system at boot, you can add an entry to the /etc/fstab file:

server_IP:/shared /mnt/shared nfs defaults 0 0

Additional Tips:

  • Securing NFS: Consider implementing additional security measures like using NFSv4, which supports stronger authentication and encryption.
  • User and Group IDs: Ensure that user and group IDs are synchronized between systems to maintain proper file ownership.
  • Monitoring and Logging: Regularly monitor NFS logs (/var/log/syslog or /var/log/messages) for any issues or anomalies.

By following these steps, you’ll have successfully prepared and configured an NFS server for sharing directories with client systems. Remember to adjust configurations based on your specific environment and security requirements.