Select Page


NFS, or Community Document Machine, is a disbursed record machine protocol that permits you to mount far off directories to your server. This allows you to organize cupboard space in a special location and write to that area from more than one purchasers. NFS supplies a rather fast and simple approach to get entry to far off programs over a community and works smartly in eventualities the place the shared assets should be accessed steadily.

On this information, we’re going to pass over easy methods to set up the elements wanted for NFS capability, configure NFS mounts, and unmount an NFS far off percentage.


We can use two servers on this educational, with one sharing a part of its filesystem with the opposite. To observe alongside, you’ll want:

  • Two Ubuntu 18.04 servers. Each and every of those will have to have a non-root person with sudo privileges configured, a easy firewall arrange with UFW, and personal networking, if it’s to be had to you.

During this educational, we discuss with the server that stocks its directories because the host and the server that mounts those directories because the consumer. With a purpose to stay them instantly, we’ll use the next IP addresses as stand-ins for the host and consumer values:

  • Host:
  • Consumer:

When those IP addresses seem in instructions and configuration information, it is important to change them with your individual respective host and consumer IP addresses.

Step 1 — Downloading and Putting in the Parts

We’ll start by means of putting in the essential elements on each and every server.

At the Host

At the host server, set up the nfs-kernel-server bundle, which can will let you percentage your directories. Since that is the primary operation that you are acting with apt on this consultation, refresh your native bundle index prior to the set up:

  • sudo apt replace
  • sudo apt set up nfs-kernel-server

As soon as those applications are put in, transfer to the consumer server.

At the Consumer

At the consumer server, we want to set up a bundle referred to as nfs-common, which supplies NFS capability with out together with unneeded server elements. Once more, refresh the native bundle index previous to set up to make certain that you may have up-to-date data:

  • sudo apt replace
  • sudo apt set up nfs-common

Now that each servers have the essential applications, we will be able to get started configuring them.

Step 2 — Growing the Percentage Directories at the Host

We are going to percentage two separate directories, with other configuration settings, with the intention to illustrate two key ways in which NFS mounts will also be configured with admire to superuser get entry to.

Superusers can do the rest any place on their machine. On the other hand, NFS-mounted directories don’t seem to be a part of the machine on which they’re fixed, so by means of default, the NFS server refuses to accomplish operations that require superuser privileges. This default restriction signifies that superusers at the consumer can not write information as root, reassign possession, or carry out some other superuser duties at the NFS mount.

From time to time, then again, there are relied on customers at the consumer machine who want to carry out those movements at the fixed record machine however who haven’t any want for superuser get entry to at the host. You’ll be able to configure the NFS server to permit this to permit this, even though it introduces a component of chance, as this type of person may acquire root get entry to to all of the host machine.

Instance 1: Exporting a Common Function Mount

Within the first instance, we’ll create a general-purpose NFS mount that makes use of default NFS conduct to makes it tricky for a person with root privileges at the consumer device to engage with the host the usage of the ones consumer superuser privileges. You could use one thing like this to retailer information that have been uploaded the usage of a content material control machine or to make space for customers to simply percentage challenge information.

First, make a percentage listing referred to as nfs:

  • sudo mkdir /var/nfs/total -p

Since we’re growing it with sudo, the listing is owned by means of the root person at the host.


Four drwxr-xr-x 2 root root 4096 Jul 25 15:26 .

NFS will translate any root operations at the consumer to the no person:nogroup credentials as a safety measure. Due to this fact, we want to exchange the listing possession to compare the ones credentials.

  • sudo chown no person:nogroup /var/nfs/total

You’re now in a position to export this listing.

Instance 2: Exporting the House Listing

In our 2d instance, the objective is to make person house directories saved at the host to be had on consumer servers, whilst permitting relied on directors of the ones consumer servers the get entry to they want to comfortably organize customers.

To try this, we’ll export the /house listing. Because it already exists, we don’t want to create it. We gained’t exchange the permissions, both. If we did, it would result in a variety of problems for any individual with a house listing at the host device.

Step 3 — Configuring the NFS Exports at the Host Server

Subsequent, we’ll dive into the NFS configuration record to arrange the sharing of those assets.

Open the /and so on/exports record on your textual content editor with root privileges:

The record has feedback appearing the overall construction of each and every configuration line. The syntax is mainly:

/and so on/exports

directory_to_share    consumer(share_option1,...,share_optionN)

We’ll want to create a line for each and every of the directories that we plan to percentage. Since our instance consumer has an IP of, our traces will seem like the next. Make sure to exchange the IP deal with proven right here to that of your consumer:

/and so on/exports


Right here, we’re the usage of the similar configuration choices for each directories except for no_root_squash. Let’s check out what each and every of those choices imply:

  • rw: This feature offers the consumer pc each learn and write get entry to to the amount.
  • sync: This feature forces NFS to jot down adjustments to disk prior to replying. This leads to a extra solid and constant atmosphere because the answer displays the true state of the far off quantity. On the other hand, it additionally reduces the rate of record operations.
  • no_subtree_check: This feature prevents subtree checking, which is a procedure the place the host should test whether or not the record is in truth nonetheless to be had within the exported tree for each and every request. This will motive many issues when a record is renamed whilst the consumer has it opened. In virtually all circumstances, it’s higher to disable subtree checking.
  • no_root_squash: Through default, NFS interprets requests from a root person remotely right into a non-privileged person at the server. This was once supposed as safety function to stop a root account at the consumer from the usage of the record machine of the host as root. no_root_squash disables this conduct for sure stocks.

If you end up completed making your adjustments, save and shut the record. Then, to make the stocks to be had to the purchasers that you simply configured, restart the NFS server with the next command:

  • sudo systemctl restart nfs-kernel-server

Ahead of you’ll in truth use the brand new stocks, then again, you’ll want to make sure that site visitors to the stocks is authorized by means of firewall laws.

Step 4 — Adjusting the Firewall at the Host

First, let’s test the firewall standing to look if it’s enabled and, if that is so, to look what is these days approved:


Standing: lively To Motion From -- ------ ---- OpenSSH ALLOW Any place OpenSSH (v6) ALLOW Any place (v6)

On our machine, handiest SSH site visitors is being allowed thru, so we’ll want to upload a rule for NFS site visitors.

With many programs, you’ll use sudo ufw app listing and permit them by means of title, however nfs isn’t a kind of. On the other hand, as a result of ufw additionally assessments /and so on/services and products for the port and protocol of a carrier, we will be able to nonetheless upload NFS by means of title. Easiest observe recommends that you simply permit probably the most restrictive rule that may nonetheless permit the site visitors you wish to have to allow, so slightly than enabling site visitors from simply any place, we’ll be particular.

Use the next command to open port 2049 at the host, being positive to change your consumer’s IP deal with:

  • sudo ufw permit from to any port nfs

You’ll be able to check the exchange by means of typing:

You will have to see site visitors allowed from port 2049 within the output:


Standing: lively To Motion From -- ------ ---- OpenSSH ALLOW Any place 2049 ALLOW OpenSSH (v6) ALLOW Any place (v6)

This confirms that UFW will handiest permit NFS site visitors on port 2049 from our consumer device.

Step 5 — Growing Mount Issues and Mounting Directories at the Consumer

Now that the host server is configured and serving its stocks, we’ll get ready our consumer.

With a purpose to make the far off stocks to be had at the consumer, we want to mount the directories at the host that we need to percentage to drain directories at the consumer.

Notice: If there are information and directories on your mount level, they are going to change into hidden once you mount the NFS percentage. To steer clear of the lack of essential information, make sure that when you mount in a listing that already exists that the listing is empty.

We’ll create two directories for our mounts:

  • sudo mkdir -p /nfs/total
  • sudo mkdir -p /nfs/house

Now that we have got a location to position the far off stocks and we’ve got opened the firewall, we will be able to mount the stocks by means of addressing our host server, which on this information is

  • sudo mount /nfs/total
  • sudo mount /nfs/house

Those instructions will mount the stocks from the host pc onto the consumer device. You’ll be able to double-check that they fixed effectively in numerous techniques. You’ll be able to test this with a simple mount or findmnt command, however df -h supplies a extra simply readable output that illustrates how disk utilization is displayed in a different way for the NFS stocks:


Filesystem Measurement Used Avail Use% Fixed on udev 238M 0 238M 0% /dev tmpfs 49M 628Okay 49M 2% /run /dev/vda1 20G 1.2G 18G 7% / tmpfs 245M 0 245M 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 245M 0 245M 0% /sys/fs/cgroup tmpfs 49M 0 49M 0% /run/person/0 20G 1.2G 18G 7% /nfs/house 20G 1.2G 18G 7% /nfs/total

Either one of the stocks we fixed seem on the backside. As a result of they have been fixed from the similar record machine, they display the similar disk utilization. To look how a lot area is in truth getting used below each and every mount level, use the disk utilization command du and the trail of the mount. The -s flag supplies a abstract of utilization slightly than showing the utilization for each and every record. The -h prints human-readable output.

For instance:


36Okay /nfs/house

This displays us that the contents of all of the house listing is the usage of handiest 36Okay of the to be had area.

Step 6 — Trying out NFS Get entry to

Subsequent, let’s take a look at get entry to to the stocks by means of writing one thing to each and every of them.

Instance 1: The Common Function Percentage

First, write a take a look at record to the /var/nfs/total percentage:

  • sudo contact /nfs/total/total.take a look at

Then, test its possession:

  • ls -l /nfs/total/total.take a look at


-rw-r--r-- 1 no person nogroup Zero Aug 1 13:31 /nfs/total/total.take a look at

As a result of we fixed this quantity with out converting NFS’s default conduct and created the record because the consumer device’s root person by means of the sudo command, possession of the record defaults to no person:nogroup. consumer superusers gained’t be capable of carry out standard administrative movements, like converting the landlord of a record or growing a brand new listing for a gaggle of customers, in this NFS-mounted percentage.

Instance 2: The House Listing Percentage

To match the permissions of the Common Function percentage with the House Listing percentage, create a record House Listing the similar approach:

  • sudo contact /nfs/house/house.take a look at

Then take a look at the possession of the record:

  • ls -l /nfs/house/house.take a look at


-rw-r--r-- 1 root root Zero Aug 1 13:32 /nfs/house/house.take a look at

We created house.take a look at as root the usage of the sudo command, precisely the similar approach we created the total.take a look at record. On the other hand, on this case it’s owned by means of root as a result of we overrode the default conduct after we specified the no_root_squash possibility in this mount. This permits our root customers at the consumer device to behave as root and makes the management of person accounts a lot more handy. On the identical time, it method we don’t have to offer those customers root get entry to at the host.

Step 7 — Mounting the Faraway NFS Directories at Boot

We will mount the far off NFS stocks routinely at boot by means of including them to /and so on/fstab record at the consumer.

Open this record with root privileges on your textual content editor:

On the backside of the record, upload a line for each and every of our stocks. They’re going to seem like this:

/and so on/fstab

. . .    /nfs/total   nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 Zero 0       /nfs/house      nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 Zero 0

Notice: You’ll be able to to find extra details about the choices we’re specifying right here within the NFS guy web page. You’ll be able to get entry to this by means of working the next command:

The consumer server will routinely mount the far off walls at boot, even though it will take a couple of moments to determine the relationship and for the stocks to be to be had.

Step 8 — Unmounting an NFS Faraway Percentage

In case you now not need the far off listing to be fixed to your machine, you’ll unmount it by means of shifting out of the proportion’s listing construction and unmounting, like this:

  • cd ~
  • sudo umount /nfs/house
  • sudo umount /nfs/total

This may increasingly take away the far off stocks, leaving handiest your native garage obtainable:


Filesystem Measurement Used Avail Use% Fixed on /dev/vda 59G 1.3G 55G 3% / none 4.0K 0 4.0K 0% /sys/fs/cgroup udev 2.0G 12Okay 2.0G 1% /dev tmpfs 396M 320Okay 396M 1% /run none 5.0M 0 5.0M 0% /run/lock none 2.0G 0 2.0G 0% /run/shm none 100M 0 100M 0% /run/person

In case you additionally need to save you them from being remounted at the subsequent reboot, edit /and so on/fstab and both delete the road or remark it out by means of hanging a # image initially of the road. You’ll be able to additionally save you auto-mounting by means of taking away the auto possibility, which can will let you mount it manually.


On this educational, we created an NFS host and illustrated some key NFS behaviours by means of growing two other NFS mounts, which we shared with our NFS consumer. In case you’re having a look to put in force NFS in manufacturing, it’s essential to notice that the protocol itself isn’t encrypted. In circumstances the place you’re sharing information which can be supposed to be publicly obtainable, this doesn’t motive any severe issues.

In case you’re the usage of NFS for personal knowledge, then again, you’ll want to come to a decision how you wish to have to give protection to that knowledge. You may be able to course NFS over SSH or a VPN connection to create a extra safe enjoy, however this steadily comes with a vital relief in efficiency. If efficiency is a matter, believe SSHFS. It’s reasonably slower than unencrypted NFS site visitors, however typically a lot quicker than tunnelled NFS. Kerberos authenticated encryption for NFS is another choice to discover.