---
title: Setting up an NFS server and connecting to it
description: This is a simple guide to installing an NFS server on CentOS. The guide should work fine for other operating systems; also, change the yum commands for apt or the equivalent for your distribution. There may be some slight package…
url: "https://www.clouvider.com/knowledge_base/setting-up-an-nfs-server-and-connecting-to-it/"
updated: "2021-12-22"
category: Guides / Linux
tags:
  - CentOS
  - NFS
  - Server
---

# Setting up an NFS server and connecting to it

This is a simple guide to installing an NFS server on CentOS. The guide should work fine for other operating systems; also, change the yum commands for apt or the equivalent for your distribution. There may be some slight package name variations.

## Server

First of all, let's make a directory to share with the NFS server:
 *NOTE: Do not create an NFS share in a /home directory unless you know what you are doing; this will cause permissions and possible security issues*

```bash
mkdir /srv/nfsshare1
```

Install the NFS server:

```bash
yum install nfs-utils
```

Now the server is installed, you need to update your permissions on the shared directory:

```bash
chmod -R 755 /srv/nfsshare1
chown nfsnobody:nfsnobody /srv/nfsshare1
```

Enable and start the required services for the NFS server:

```bash
systemctl enable rpcbind
systemctl enable nfs-server
systemctl enable nfs-lock
systemctl enable nfs-idmap
systemctl start rpcbind
systemctl start nfs-server
systemctl start nfs-lock
systemctl start nfs-idmap
```

Now we need to create an export file, which is used to tell the NFS server what to share. Let's create a file named /etc/exports and enter the following into it:

```bash
/srv/nfsshare1    23.56.188.9(rw,sync,no_root_squash,no_all_squash)
```

*NOTE: Replace 23.56.188.9 with the IP of your server; this one was just made up for the guide*

Restart the NFS server:

```bash
systemctl restart nfs-server
```

You will need to enable ports 111 TCP and 2049 TCP+UDP in your iptabes/firewall.

## Client

We need to install the nfs-utils package:

```bash
yum install nfs-utils
```

Let's make a target directory/mount point:

```bash
mkdir /mnt/nfs1
```

Now to connect to the NFS server and mount the shared directory:

```bash
 mount -t nfs 23.56.188.9:/srv/nfsshare1 /mnt/nfs1/
```

When you run 'df -kh' you will see the NFS directory mounted on your client.

You can add this as a permanent mount using the /etc/fstab file and adding the following line to the end of that file:

```bash
23.56.188.9:/srv/nfsshare1    /mnt/nfs1   nfs defaults 0 0
```
