How to Install and Configure NFS on CentOS and Access It from Linux and Windows
This guide walks through the principles of NFS, installs and configures the NFS server on CentOS 7.7, sets up shared directories, and demonstrates how Linux and Windows clients can mount and use the NFS shares, including script automation for persistent mapping.
1. NFS Principles
NFS (Network File System) enables data sharing across different operating systems using the RPC protocol in a client/server model, typically on port 2049. RHEL7 defaults to NFSv4.
# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core) # grep nfs /etc/services
nfs 2049/tcp nfsd shilp # Network File System
nfs 2049/udp nfsd shilp # Network File System
nfs 2049/sctp nfsd shilp # Network File System2. Install NFS Server
The NFS server requires two packages: nfs-utils (provides NFS commands and monitoring) and rpcbind (supports secure NFS RPC connections).
# yum -y install nfs-utils # rpm -qa | grep nfs && rpm -qa | grep rpcbind
libnfsidmap-0.25-19.el7.x86_64
nfs-utils-1.3.0-0.65.el7.x86_64
rpcbind-0.2.0-48.el7.x86_643. Configure NFS Server
Create a shared directory and set permissions:
# mkdir -p /tmp/share
# chmod o+rwx /tmp/share
# ll -d /tmp/share
drwxrwxrwx 2 root root 6 Mar 16:38 /tmp/shareEdit /etc/exports to define which clients can access the share and with what options:
/tmp/share 192.168.1.0/24(rw,sync,all_squash) # all_squash maps all users to nfsnobodyStart the services and export the configuration:
# systemctl start rpcbind
# systemctl start nfs
# exportfs -rv
exporting 192.168.1.0/24:/tmp/shareVerify the export list:
# showmount -e localhost
Export list for localhost:
/tmp/share 192.168.1.0/244. Linux Client Access
Install the client utilities, create a mount point, and mount the NFS share:
# yum -y install nfs-utils
# mkdir /shares
# showmount -e 192.168.1.251
Export list for 192.168.1.251:
/tmp/share 192.168.1.0/24
# mount -t nfs 192.168.1.251:/tmp/share /shares
# df -h
Filesystem Size Used Avail Use% Mounted on
192.168.1.251:/tmp/share 37G 1.6G 36G 5% /sharesUse the shared directory:
# cd /shares/
# touch 123.txt
# mkdir dir
# ls
123.txt dirUnmount when finished:
# umount /shares5. Windows Client Access
Enable the NFS client feature in Windows (e.g., Windows 7) via Control Panel → Programs → Turn Windows features on or off, checking "NFS Client" and related tools.
After installation, mount the NFS share using the command prompt: mount \\192.168.1.251\tmp\test Z: Verify the mapped drive in Windows Explorer. For persistent mapping, create a batch script (e.g., nfs.bat) with the following content and place it in the startup folder:
# nfs.bat content
@echo off
start "C:\Windows\System32\cmd.exe"
net use Z: \\192.168.1.251\tmp\test
taskkill /f /im cmd.exe
exitRunning this script at startup automatically maps the NFS share to drive Z: after each reboot.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
