How to Install and Configure an NFS Server on Ubuntu 18.04?


NFS or Network File System is a widely used protocol that allows remote clients to access shared files over a network. Installing and configuring an NFS server on Ubuntu 18.04 is a straightforward process, but it requires some basic knowledge of Ubuntu commands and file systems. In this article, we will walk you through steps to install and configure an NFS server on Ubuntu 18.04.

Step 1: Update System

Before installing any software, it's always a good practice to update system. To do this, open terminal and run following command −

sudo apt update && sudo apt upgrade

This command will update package list and upgrade packages already installed on system.

Step 2: Install NFS Server

To install NFS server package, run following command −

sudo apt install nfs-kernel-server

This command will install NFS server package on Ubuntu system.

Step 3: Configure NFS Exports

Once NFS server package is installed, we need to configure NFS exports. Exports are directories or files that are shared with remote clients. To configure exports, we need to edit exports file located in /etc/exports directory.

sudo nano /etc/exports

In this file, you need to add directories or files that you want to share with remote clients. For example, if you want to share /home directory, add following line to file −

/home *(rw,sync,no_subtree_check)

This line allows any remote client to access /home directory with read and write permission. options used in this line are explained below −

  • rw − This option allows read and write permission to remote clients.

  • sync − This option ensures that changes made on NFS server are immediately reflected on remote clients.

  • no_subtree_check − This option disables subtree checking, which is used to ensure that path provided by remote client is within shared directory.

  • You can add multiple lines to share different directories or files. Once you have added directories, save and close file.

Step 4: Export NFS Shares

After configuring exports, we need to export them to make them available to remote clients. To export shares, run following command −

sudo exportfs -a

This command exports all directories listed in /etc/exports file.

Step 5: Configure Firewall

If you have a firewall enabled on your system, you need to allow NFS traffic to pass through it. To do this, run following commands −

sudo ufw allow from <client_ip> to any port nfs
sudo ufw allow from <client_ip> to any port 2049

Replace <client_ip> with IP address of remote client that you want to allow access to NFS server.

Step 6: Start and Enable NFS Server

To start NFS server, run following command −

sudo systemctl start nfs-kernel-server

To enable NFS server to start automatically at boot time, run following command −

sudo systemctl enable nfs-kernel-server

Step 7: Verify NFS Server

To verify that NFS server is running and exports are working, you can use showmount command. This command displays shared directories and files from NFS server.

showmount -e <nfs_server_ip>

Replace <nfs_server_ip> with IP address of NFS server.

machines on a network, and with these steps, you should now have a working NFS server that is ready to share files.

Remember that security is always a concern when sharing files over a network. Make sure to only share directories and files that are necessary and to restrict access to those shares to only clients that need them. You should also consider enabling encryption or using a VPN to secure traffic between NFS server and clients.

Additionally, NFS has some limitations when it comes to sharing files between different operating systems. If you need to share files between Windows and Linux, for example, you may want to consider using a different protocol like Samba.

Overall, NFS is a reliable and widely used protocol for sharing files between Linux machines on a network. By following steps outlined in this article, you can easily set up an NFS server on Ubuntu 18.04 and start sharing files with remote clients.

Here are some additional tips and considerations to keep in mind when installing and configuring an NFS server on Ubuntu 18.04 −

Configuring NFS exports can be complex, especially when it comes to setting permissions and access control. Make sure to read NFS exports man pages (man exports) to learn more about available options and how to use them.

By default, NFS uses NFSv4 protocol. However, if you need to use an older version of protocol, you can specify it in exports file using fsid option. For example, to use NFSv3, add following line to exports file: /home *(rw,sync,no_subtree_check,fsid=0).

If you want to limit number of remote clients that can access NFS server, you can specify their IP addresses or hostnames in exports file. For example, to allow only a specific IP address to access /home directory, add following line to exports file: /home 192.168.1.100(rw,sync,no_subtree_check).

NFS can be slow over long distances or slow network connections. If you are experiencing slow performance, you can try tweaking NFS server settings or using a different protocol like SSHFS.

If you need to mount an NFS share on a client machine, you can use mount command. For example, to mount /home directory on a client machine with IP address 192.168.1.100, run following command: sudo mount -t nfs 192.168.1.10:/home /mnt/nfs.

If you are experiencing issues with NFS, you can check NFS server logs for error messages. logs are usually located in /var/log directory and are named syslog or messages.

Here are a few more tips and tricks to help you get most out of your NFS server on Ubuntu 18.04 −

  • Use NFSv4 ACLs for Granular Access Control − NFSv4 introduced Access Control Lists (ACLs) which can be used to provide granular access control to shared files and directories. NFSv4 ACLs allow you to set permissions for individual users and groups, as well as set default permissions for new files and directories. To use NFSv4 ACLs, you need to enable them on NFS server and mount NFS share with acl option. For example, sudo mount -t nfs -o acl 192.168.1.10:/home /mnt/nfs.

  • Optimize NFS Performance − NFS performance can be improved by tuning NFS server and client settings. For example, you can increase number of NFS server threads, adjust buffer sizes, and enable caching. You can also use tools like nfsstat and iostat to monitor NFS performance and identify bottlenecks.

  • Secure NFS with Kerberos − NFS traffic is transmitted in plaintext by default, which can be a security risk. To secure NFS traffic, you can use Kerberos authentication and encryption. Kerberos is a network authentication protocol that provides strong authentication and encryption for network traffic. Enabling Kerberos on an NFS server and client requires some additional configuration, but it provides a more secure way to share files over network.

  • Use NFS in a Cluster − NFS can be used in a clustered environment to provide high availability and fault tolerance. Clustered NFS solutions use technologies like Pacemaker, Corosync, and DRBD to provide active-passive or active-active NFS clusters. Clustering NFS allows you to provide uninterrupted file access to clients even in event of server failures.

  • Monitor NFS Performance and Usage − It's important to monitor NFS performance and usage to identify issues and optimize performance. You can use tools like nfsstat, iostat, and sar to monitor NFS performance and usage. You can also use a monitoring solution like Nagios or Zabbix to monitor NFS server health and alert you to issues.

Conclusion

In this article, we have discussed steps to install and configure an NFS server on Ubuntu 18.04. NFS is a reliable and flexible way to share files between Linux machines on a network. By following steps outlined in this article and implementing tips and tricks discussed, you can set up a powerful and secure NFS server on Ubuntu 18.04 that meets your needs.

Updated on: 12-May-2023

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements