/ unix

Creating NFS Shares

There comes a time when you're working on multiple servers or nodes that need the same files or resources to function. You can upload everything you need to each instance, but that doesn't scale well if you have hundreds or thousands to manage!

Setting up a network file system share will allow you to stage all of the necessary resources in a central location for your servers to use. No more having to upload resources to individual nodes.

Getting Started

For this demo, I'll use a Fedora server and a Debian client.

IP Addresses to remember:

Fedora Server - 192.168.232.131

Debian Client - 192.168.232.130

  1. Install nfs-util

dnf install nfs-utils -y

2. Allow NFS to go through the firewall. (I'm using firewalld)

firewall-cmd --add-service=nfs --permanent

3. Reload the firewalld for the settings to take effect.

firewall-cmd --reload

4. Verify firewalld settings for NFS.

firewalld-cmd --list-all

You should see NFS in the list of services:

[scleft@fedora-server]# firewall-cmd --list-all
FedoraServer (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens33
  sources:
  services: ssh dhcpv6-client cockpit nfs
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

5. Enable and Start NFS

systemctl enable nfs && systemctl start nfs

6. Create a directory on the server to be shared to the clients.

mkdir /var/myshare

chmod -R 755 /var/myshare

7. Allow our debian client to connect to the share using's IP address.

vim /etc/exports

Your file should look something like this:

/var/myshare    192.168.232.130(rw,sync,no_root_squash,no_all_squash)

8. Restart NFS server

systemctl restart nfs-server

Now lets connect to the debian client and configure it to connect to the NFS share.

9. Install NFS common

apt install nfs-common -y

10. Create a directory that will used as the NFS mount point.

mkdir /var/myshare

11. Mount the share.

mount -t nfs 192.168.232.131:/var/myshare /var/myshare

12. Verify it's there!

When you do df you should see something similar on the bottom.

scleft@debian-client:/# df 
Filesystem                    Size  Used Avail Use% Mounted on
udev                          478M     0  478M   0% /dev
tmpfs                          98M  4.4M   94M   5% /run
/dev/mapper/debian--vg-root   4.9G  920M  3.7G  20% /
tmpfs                         490M     0  490M   0% /dev/shm
tmpfs                         5.0M     0  5.0M   0% /run/lock
tmpfs                         490M     0  490M   0% /sys/fs/cgroup
/dev/mapper/debian--vg-tmp    399M  2.3M  372M   1% /tmp
/dev/sda1                     236M   63M  162M  28% /boot
/dev/mapper/debian--vg-var    2.0G  201M  1.6G  11% /var
/dev/mapper/debian--vg-home    17G   45M   16G   1% /home
tmpfs                          98M     0   98M   0% /run/user/1000
192.168.232.131:/var/myshare   15G  2.2G   13G  15% /var/myshare				

13. Test it!

Connect back to the fedora server and create a test file. If you see the same test file on your debian client then you can safely say, it's working!

14. Make the mount permanent.

This mount will disappear when the client reboots, to make it permanent; edit the fstab file.

vim /etc/fstab

Add the following lines.

192.168.232.131:/var/myshare 	/var/myshare       nfs rw,async,hard,intr,noexec 0 0
Creating NFS Shares
Share this