This article is going to take you through on how to Install NFS Server on Ubuntu 22.04. The Network File System (NFS) is a client/server program that allows a computer user to access, store, and update files on a remote computer. NFS is one of several Distributed File System (DFS) standards for network attached storage (NAS).
How to Install NFS Server on Ubuntu 22.04
- Update your packages to current version.
sudo apt update
- Then set host name
sudo hostnamectl set-hostname nfs.example.com --static
Install NFS Server
- After updating your packages and setting up host name, you can now install NFS server using the following command.
sudo apt install nfs-kernel-server
Sample output
Reading package lists... Done Building dependency tree... Done Reading state information... Done The following packages were automatically installed and are no longer required: fonts-open-sans gir1.2-gnomebluetooth-1.0 i965-va-driver intel-media-va-driver kwayland-data libaacs0 libavcodec58 libavformat58 libavutil56 libbdplus0 libbluray2 libchromaprint1 libcodec2-1.0 libdouble-conversion3 libgme0 libgsm1 libigdgmm12 libkf5waylandclient5 libmd4c0 libmfx1 libminizip1 libmng2 libnorm1 libopenal-data libopenal1 libopenmpt0 libpcre2-16-0 libpgm-5.3-0 libqrcodegencpp1 libqt5core5a libqt5dbus5 libqt5gui5 libqt5network5 libqt5svg5 libqt5waylandclient5 libqt5widgets5 librabbitmq4 librlottie0-1 libshine3 libsndio7.0 libsrt1.4-gnutls libssh-gcrypt-4 libswresample3 libswscale5 libudfread0 libva-drm2 libva-x11-2 libva2 libvdpau1 libx264-163 libxcb-record0 libxcb-screensaver0 libxcb-xinerama0 libxcb-xinput0 libxvidcore4 libzmq5 libzvbi-common libzvbi0 mesa-va-drivers mesa-vdpau-drivers qt5-gtk-platformtheme qt5-image-formats-plugins qttranslations5-l10n va-driver-all vdpau-driver-all Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: keyutils libevent-core-2.1-7 libnfsidmap1 nfs-common rpcbind Suggested packages: open-iscsi watchdog The following NEW packages will be installed: keyutils libevent-core-2.1-7 libnfsidmap1 nfs-common nfs-kernel-server rpcbind 0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded. Need to get 616 kB of archives. After this operation, 2,235 kB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 libevent-core-2.1-7 amd64 2.1.12-stable-1build3 [93.9 kB] Get:2 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 libnfsidmap1 amd64 1:2.6.1-1ubuntu1 [43.5 kB] Get:3 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 rpcbind amd64 1.2.6-2build1 [46.6 kB] Get:4 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 keyutils amd64 1.6.1-2ubuntu3 [50.4 kB] Get:5 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 nfs-common amd64 1:2.6.1-1ubuntu1 [241 kB] Get:6 http://ke.archive.ubuntu.com/ubuntu jammy/main amd64 nfs-kernel-server amd64 1:2.6.1-1ubuntu1 [140 kB] Fetched 616 kB in 1s (986 kB/s)
- NFS should be up and running, check its status.
sudo systemctl status nfs-server
Sample output
● nfs-server.service - NFS server and services Loaded: loaded (/lib/systemd/system/nfs-server.service; enabled; vendor preset: enabled) Active: active (exited) since Thu 2022-04-14 12:25:10 EAT; 2min 36s ago Main PID: 8868 (code=exited, status=0/SUCCESS) CPU: 8ms Apr 14 12:25:10 nfs.itnixpro.com systemd[1]: Starting NFS server and services... Apr 14 12:25:10 nfs.itnixpro.com exportfs[8867]: exportfs: can't open /etc/exports for reading Apr 14 12:25:10 nfs.itnixpro.com systemd[1]: Finished NFS server and services.
Setup NFS directory share
- The NFS directory share is where we will store files that will be shared across the local area network. It will be created under the /mnt/directory_name, lets create the directory using the following command.
sudo mkdir /mnt/my_data
- Next, assign ownership and permissions
sudo chown nobody:nogroup /mnt/my_data
sudo chmod -R 777 /mnt/my_data
Configure Exports for client
- Edit the exports configuration file to allow client access. Open the exports file using the following command.
sudo nano /etc/exports
- Add client that can access the NFS server using the following line in the config file. Note, you can add several lines with different clients IP to add more clients.
/mnt/my_data CLIENT-IP(rw,sync,no_subtree_check)
Command above meaning;
- rw-Read and Write )
- sync-Write changes to disk before applying them)
- no_subtree_check-Avoid subtree checking )
Next export the shared directory using the following command.
sudo exportfs -a
Allow NFS Share Access on Firewall
- If you are using firewall, allow NFS using the following command.
sudo ufw allow from 192.168.0.101/24 to any port nfs
- By default NFS runs on port 2049, reload firewall to apply changes.
sudo ufw reload
- Then check status using the command below.
sudo ufw status
Install and Configure NFS Client
- Start by updating your client packages.
sudo apt update
- Then install NFS client package using the command below.
sudo apt install nfs-common
Mounting NFS Share on the Client
- Create directory using the following command which will be used to mount the NFS share from the NFS server.
sudo mkdir -p /mnt/client_directory
- After creating the mount directory, mount the remote NFS share directory using the command below.
sudo mount SERVER-IP:/mnt/my_data /mnt/client_directory
Test NFS Share
- On the NFS server, navigate to your directory share and create a test file.
cd /mnt/my_data
touch nfs_demo.txt
- Then on your client machine, list content of mounted share directory.
ls /mnt/client_directory
You should be able to see the contents of server share in the client directory.
- That marks the end of our article, Cheers! You have learned how to Install NFS Server on Ubuntu 22.04.
Read more about NFS commands in the man page
Other Tutorials
Synchronize Files between multiple devices using Syncthing