This page looks best with JavaScript enabled

NFS Deployment and Mounting

 ·  ☕ 1 min read

NFS (Network File System) is used to share directories over the network; once the client mounts them, they can be read and written like a local disk. This post covers deploying an NFS service on CentOS and Ubuntu, and how to mount a remote NFS directory on each system.

1. exports Configuration

Both the CentOS and Ubuntu server sides configure shared directories through /etc/exports. Each line has the format: 共享目录 客户端地址(选项).

1
/data/  192.168.10.0/24(rw,sync,no_root_squash,no_all_squash)
  • /data/: the directory to share
  • 192.168.10.0/24: the client IP range allowed to access it; * means no restriction
  • rw: readable and writable
  • sync: synchronous writes
  • no_root_squash: the client’s root is also mapped to root on the server
  • no_all_squash: preserve the client user’s UID/GID

After modifying /etc/exports, you must restart the NFS service for the change to take effect:

1
systemctl restart nfs-server

2. CentOS 7

2.1 Deploying the NFS Service

Install:

1
yum install -y nfs-utils

Create the shared directory and edit /etc/exports:

1
mkdir -p /data

Start it and enable it at boot:

1
2
systemctl start nfs-server.service
systemctl enable nfs-server.service

Verify:

1
exportfs -v

2.2 Mounting NFS

Install the client tools:

1
yum install -y nfs-utils

Mount:

1
2
mkdir -p /mnt/nfs
mount -t nfs 服务器IP:/data /mnt/nfs

To mount automatically at boot, edit /etc/fstab and add:

1
服务器IP:/data  /mnt/nfs  nfs  defaults  0  0

Unmount:

1
umount /mnt/nfs

3. Ubuntu

3.1 Deploying the NFS Service

Install:

1
apt-get install -y nfs-kernel-server

Create the shared directory and edit /etc/exports:

1
mkdir -p /data

Start it and enable it at boot:

1
2
systemctl start nfs-server.service
systemctl enable nfs-server.service

Verify:

1
exportfs -v

3.2 Mounting NFS

Install the client tools:

1
apt-get install -y nfs-common

Mount:

1
2
mkdir -p /mnt/nfs
mount -t nfs 服务器IP:/data /mnt/nfs

To mount automatically at boot, edit /etc/fstab and add:

1
服务器IP:/data  /mnt/nfs  nfs  defaults  0  0

Unmount:

1
umount /mnt/nfs

4. macOS

macOS has a built-in NFS client, so no extra installation is needed; it acts only as a client mounting a remote directory.

Mount:

1
2
mkdir -p ~/nfs
mount_nfs 服务器IP:服务器目录 客户端目录

For example:

1
mount_nfs 1.2.3.4:/data /Users/username/nfs/

Unmount:

1
umount /Users/username/nfs/

微信公众号
WRITTEN BY
微信公众号