Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / Linux / CentOS / Configuring NFS Server and Client on Linux CentOS/RHEL

May 10, 2023 CentOSLinuxQuestions and AnswersRHEL

Configuring NFS Server and Client on Linux CentOS/RHEL

Network File System (NFS) is a distributed file system protocol for sharing files and folders. NFS is based on the Remote Procedure Protocol (ONC RPC). NFS allows to mount remote file systems over the network. Remember that by default data are not encrypted when using NFS, and clients are not authenticated (access can be limited by IP).

NFS is easy to configure both on the server and client-side. In this article, we’ll show how to install and configure an NFS server, and then we will connect an NFS share on a client. This article is based on RPM-based Linux distributions (CentOS, RHEL, Fedora, etc.).

Contents:
  • How to Install and Configure an NFS Server on Linux CentOS
  • Configuring NFS Client on CentOS

How to Install and Configure an NFS Server on Linux CentOS

By default, nfs is already installed in CentOS with the Standard package. If you have removed NFS components or used the Minimal Install mode for your server, you can install the NFS package using yum (or dnf) package manager:

In CentOS 8:

# dnf install nfs-utils -y

I had the package installed:

install nfs tools on linux centos

The current NFS server version supports NFSv3 and NFSv4 protocol versions. NFSv2 is disabled by default. You can get a list of supported NFS versions using this command:

cat /proc/fs/nfsd/versions

After you have installed all packages you need, start nfs-server and rpcbind services, and add them to startup:

# systemctl enable rpcbind
# systemctl enable nfs-server
# systemctl start rpcbind
# systemctl start nfs-server

If you want to use NFSv4.1/4.2 only, you don’t need to run rpcbind.

If you are using firewalld on your Linux host, open the following ports:

# firewall-cmd --permanent --add-port=111/tcp
# firewall-cmd --permanent --add-port=20048/tcp
# firewall-cmd --permanent --add-service=nfs
# firewall-cmd --permanent --zone=public --add-service=nfs
# firewall-cmd --permanent --zone=public --add-service=mountd
# firewall-cmd --permanent --zone=public --add-service=rpc-bind
# firewall-cmd --reload

configure firewall rules for nfs server on linux

For those who are using iptables:

# iptables -t filter -A INPUT -p tcp --dport 111 -j ACCEPT
# iptables -t filter -A INPUT -p tcp --dport 2049 -j ACCEPT
# iptables -t filter -A INPUT -p tcp --dport 20048 -j ACCEPT
# service iptables save
# service iptables restart

Then create a directory your NFS server will share:

# mkdir -p /backup/nfs
# chmod -R 777 /backup/nfs

Publish the NFS share and assign access permissions in the configuration file containing the NFS server settings (/etc/exports).

# nano /etc/exports

Add the following line to the config to grant NFS access to all hosts in the specified IP subnet:

/backup/nfs 192.168.1.0/24(rw,sync,no_root_squash,no_all_squash)

Or you can limit access to a single IP address only:

/backup/nfs 192.168.2.24(rw,sync,no_root_squash,no_all_squash, anonuid=1000,anongid=1000) 192.168.3.100 (ro,async,no_subtree_check)

Let’s see what parameters are used to grant privileges on the NFS directory:

  • rw – grant write permissions, ro – provides read-only access
  • sync – synchronous access mode, async means that you don’t need to wait for confirmation of writing on the disk (it improves NFS performance, but reduces reliability)
  • no_root_squash – allows the root user to get access to the NFS directory from a client (usually not recommended)
  • no_all_squash – enables user authentication, all_squash – allows accessing NFS share under an anonymous user
  • no_subtree_check – disables a check that a user accessed a file in the directory (subtree_check is used by default)
  • anonuid, anongid – map NFS user/group to the specified local user/group (UID or GID)

To apply new NFS share settings, run the following command:

# exportfs -a

And restart the NFS server:

# systemctl restart nfs-server

Thus, we have finished the configuration of our NFS server and may proceed with a client configuration.

Configuring NFS Client on CentOS

To configure an NFS client, you must also install the nfs-utils package.

# yum install nfs-utils -y

Add services to startup and start them:

# systemctl enable rpcbind
# systemctl enable nfs-server
# systemctl start rpcbind
# systemctl start nfs-server

Then create a directory on a client the NFS directory will be mounted to:

# mkdir /backup

Then you can mount the remote NFS share using this command:

# mount -t nfs 192.168.0.100:/backup/nfs/ /backup

You can force the version of the NFS protocol to be used:

# mount -t nfs -o vers=4 192.168.0.100:/backup/nfs/ /backup

where IP is the address of the NFS server you have configured earlier.

mount nfs share fstab on linux

Then the connected NFS shares will be displayed in the list of mounted drives. You can read data in the directory or write to it (depending on the permissions assigned to your IP address on the NFS server). To automatically mount the NFS directory on reboot, you need to open the fstab file:

# nano /etc/fstab

And add the following line to it:

192.168.0.100:/backup/nfs/ /backup/ nfs rw,sync,hard,intr 0 0

After saving fstab, you can apply it with this command:

# mount -a

So we have configured and connected a remote NFS storage, which can be used for transparent network access to a shared resource from different hosts. You can place backups, ISO image files, etc. in your NFS directory.

0 comment
0
Facebook Twitter Google + Pinterest
previous post
Run a Script (Program) When a Specific Program Opens/Closes in Windows
next post
Searching AD Groups, Users, and Computers using Wildcards

Related Reading

How to Increase Size of Disk Partition in...

October 5, 2023

How to Use Ansible to Manage Windows Machines

September 25, 2023

Fixing ‘The Network Path Was Not Found’ 0x80070035...

August 30, 2023

How to Install and Configure Ansible on Linux

August 27, 2023

Computer Doesn’t Turn Off After Shutting Down Windows...

August 26, 2023

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023
  • How to Use Ansible to Manage Windows Machines

    September 25, 2023
  • Installing Language Pack in Windows 10/11 with PowerShell

    September 15, 2023
  • Configure Email Forwarding for Mailbox on Exchange Server/Microsoft 365

    September 14, 2023
  • How to View and Change BIOS (UEFI) Settings with PowerShell

    September 13, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • How to Configure MariaDB Master-Master/Slave Replication?
  • How to Mount Google Drive or OneDrive in Linux?
  • KVM: How to Expand or Shrink a Virtual Machine Disk Size?
  • Install and Configure SNMP on RHEL/CentOS/Fedor
  • Configuring High Performance NGINX and PHP-FPM Web Server
  • Adding VLAN Interface in CentOS/Fedora/RHEL
  • Configuring Routing on Linux (RHEL/CentOS)
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top