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

November 11, 2021 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

Turn Linux Computer into Wi-Fi Access Point (Hotspot)

April 14, 2023

0x80244010 Exceeded Max Server Round Trips: Windows Update...

April 12, 2023

Fixing the Read-Only File System Error on Linux

April 7, 2023

Find Out Which Process is Listening on a...

April 5, 2023

Attaching Host USB Devices to WSL or Hyper-V...

March 20, 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

  • Configuring Event Viewer Log Size on Windows

    May 24, 2023
  • How to Detect Who Changed the File/Folder NTFS Permissions on Windows?

    May 24, 2023
  • Enable Single Sign-On (SSO) Authentication on RDS Windows Server

    May 23, 2023
  • Allow Non-admin Users RDP Access to Windows Server

    May 22, 2023
  • How to Create, Change, and Remove Local Users or Groups with PowerShell?

    May 17, 2023
  • Fix: BSOD Error 0x0000007B (INACCESSABLE_BOOT_DEVICE) on Windows

    May 16, 2023
  • View Success and Failed Local Logon Attempts on Windows

    May 2, 2023
  • Fix: “Something Went Wrong” Error When Installing Teams

    May 2, 2023
  • Querying Windows Event Logs with PowerShell

    May 2, 2023
  • Configure Windows LAPS (Local Administrator Passwords Solution) in AD

    April 25, 2023

Follow us

  • Facebook
  • Twitter
  • RSS
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