The Network File System (NFS) is a protocol that allows you to set up storage locations on your network. When you have NFS set up, your users can treat a remote hard drive as if it were attached to their computer, just like they might a USB thumb drive. It's one of the easiest and most transparent ways to handle shared storage within an organization.

[ Free download: Advanced Linux commands cheat sheet. ]

Install NFS

NFS is a built-in function in Red Hat Enterprise Linux (RHEL) 9, but there's a package of utilities that you can install on the computer serving as the NFS host and on the Linux workstations that will interface with NFS:

$ sudo dnf install nfs-utils

On your NFS host, enable and start the NFS service:

$ sudo systemctl enable --now nfs-server

You must also start the rpcbind service, which NFS uses for port mapping:

$ sudo systemctl enable --now rpcbind

Set a shared location

On your NFS host, create a location on the filesystem to share with client computers. This could be a separate drive, a separate partition, or just a place on your server. To ensure that your storage can scale as needed, I recommend using LVM. Create the location with:

$ sudo mkdir -p /nfs/exports/myshare

Export the shared location

For the NFS service to know to broadcast the existence of your myshare shared location, you must add the location to the /etc/exports file, as well as the subnet you want to have access and the global access permissions. For example, assuming your network is 192.168.122.0/24 (with the first possible address being 192.168.122.1 and the final being 192.168.122.254), then you could do this:

$ echo "/nfs/exports/myshare 192.168.122.0/24(rw)" > /etc/exports

Note that there is no space between the network and the directory's access permissions.

Set ownership

Depending on where you created your shared location, its permissions may not be suitable for all users on your network. For example, I created /nfs/exports/myshare at the root partition of my server's hard drive, so the directories are all owned by the user root, with group root having read and execute permissions. Unless your users are members of the root group, this export is of little use to them.

How you set directory permissions is up to you and depends on how you define users and groups on your systems. It's common to manage directories by group permissions, adding users who require access to specific directories to the corresponding group. For instance, if a user is a member of the staff group, then you could set your export to staff with permissions 775:

$ sudo chown root:staff /nfs/exports/myshare
$ sudo chmod 775 /nfs/exports/myshare

This grants myshare read, write, and execute permissions for all members of the staff group.

Export the exports

The NFS server maintains a table of filesystems available to clients. To update the table, run the exportfs command along with the -r command to export all directories recursively:

$ sudo exportfs -r

Configure your firewall

For clients to reach your NFS server, you must add the NFS service to your firewall with the firewall-cmd command, and then reload the firewall rules:

$ sudo firewall-cmd --add-service nfs --permanent
$ sudo firewall-cmd --reload

Your NFS server is now active and configured for traffic.

[ Free online course: Red Hat Enterprise Linux technical overview. ]

Set up your client

Now that you've established a shared storage location on your network, you must configure your client machines to use it.

As with the server, the client machine requires the nfs-utils package:

[workstation]$ sudo dnf install nfs-utils

Next, create a mount point for the NFS share:

[workstation]$ sudo mkdir /nfs/imports/myshare

And then mount the NFS volume:

[workstation]$ sudo mount -v \
-t nfs 192.168.122.17:/nfs/exports/myshare \
/nfs/imports/myshare/

You can make this a permanent and automatic process by adding the NFS volume to the client's /etc/fstab file:

192.168.122.17:/nfs/exports/myshare   /nfs/imports/myshare/  nfs  rw 0 0

You can verify that an NFS volume is mounted with the mount command:

[workstation]$ sudo mount | grep -i nfs
192.168.122.17:/nfs/exports/myshare on /nfs/imports/myshare ...

Use NFS

If you've got more than one or two workstations, it's inefficient to set up your client machines to recognize NFS volumes by hand. Instead, use Ansible to automate the configuration of your client machines, both to set up NFS shares and to update configurations when required.

NFS makes shared storage easy and transparent for your users, and it helps encourage collaboration and shared data, so consider giving it a try.


저자 소개

Seth Kenlon is a Linux geek, open source enthusiast, free culture advocate, and tabletop gamer. Between gigs in the film industry and the tech industry (not necessarily exclusive of one another), he likes to design games and hack on code (also not necessarily exclusive of one another).

UI_Icon-Red_Hat-Close-A-Black-RGB

채널별 검색

automation icon

오토메이션

기술, 팀, 인프라를 위한 IT 자동화 최신 동향

AI icon

인공지능

고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트

open hybrid cloud icon

오픈 하이브리드 클라우드

하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요

security icon

보안

환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보

edge icon

엣지 컴퓨팅

엣지에서의 운영을 단순화하는 플랫폼 업데이트

Infrastructure icon

인프라

세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보

application development icon

애플리케이션

복잡한 애플리케이션에 대한 솔루션 더 보기

Virtualization icon

가상화

온프레미스와 클라우드 환경에서 워크로드를 유연하게 운영하기 위한 엔터프라이즈 가상화의 미래