Q. How do I install and configure NFS 4 Server under Ubuntu Linux ?
A. In order to set NFS server you need to install the following packages:
=> nfs-kernel-server – Linux NFS Server
=> nfs-common – NFS Common programs
=> portmap – The RPC portmapper
Ubuntu Linux install NFS Server
Use apt-get command to install all required packages:
$ sudo apt-get install nfs-kernel-server portmap nfs-common
Sharing directory with /etc/exports
The NFS file systems being exported / shared using /etc/exports file. You need to specify directory (file system) to share with rest of the nfs client computers. The file /etc/exports serves as the access control list for file systems which may be exported to NFS clients.
$ sudo vi /etc/exports
To export /data directory to 192.168.1.0/24 network enter the following in /etc/exports file:
/data 192.168.1.0/24(rw,rsync)
To export /sales to hostname tom and jerry, enter:
/sales tom(ro,sync) jerry(ro,sync)
To export /users to 192.168.1.0/24 in read write format, enter:
/users 192.168.1.0/24(ro,sync) jerry(rw,fsid=0,insecure,no_subtree_check,async)
Where,
- rw : Allow clients to read as well as write access
- ro : Read only access
- insecure : Tells the NFS server to use unpriveledged ports (ports > 1024).
- no_subtree_check : If the entire volume (/users) is exported, disabling this check will speed up transfers.
- async : async will speed up transfers.
Save and close the file. Just restart nfs-server:
$ sudo /etc/init.d/nfs-kernel-server restart
Now your NFS sever is sharing /sales and /data directories.
How do I access shared directories from Linux client computer?
Login to Linux desktop system and enter the following command to mount shared directories. First, create a mountpoint on your client computer:
# mkdir /mnt/data
Mount the server:
# mount nfs-server:/data /mnt/data
You can also use following syntax for NFS client version 4:
# mount -t nfs4 -o proto=tcp,port=2049 nfs-server:/data /mnt/data
OR
# mount -t nfs4 -o proto=tcp,port=2049 192.168.1.100:/data /mnt/data
Where,
- 192.168.1.100 : NFS Server IP address
- proto=tcp,port=2049 : Force to use TCP protocol i.e. mount the NFS filesystem using TCP. The numeric value of the port to connect to the NFS server on. If the port number is 0 (the default) then query the remote host’s portmapper for the port number to use. If the remote host’s NFS daemon is not registered with its portmapper, the standard NFS port number 2049 is used instead.
How do I access my files?
To access shared files use regular commands or GUI file manager:
$ cd /mnt/data
$ ls
$ mkdir office
$ pwd
See Linux NFS client how to for more information.
To see mounted file system and available disk space use df command:
$ df -h
Output:
Filesystem Size Used Avail Use% Mounted on /dev/sda2 92G 23G 65G 26% / varrun 1013M 128K 1013M 1% /var/run varlock 1013M 0 1013M 0% /var/lock udev 1013M 84K 1013M 1% /dev devshm 1013M 0 1013M 0% /dev/shm /dev/sda1 98G 22G 77G 23% /media/sda1 /dev/sda5 274G 29G 245G 11% /share /dev/sdb2 230G 4.9G 213G 3% /backup.iscsi nfs-server:/data/ 230G 31G 188G 14% /mnt/data
How do I see all shared directories from client computer?
Use showmount command to query the mount daemon (NFS Server) on a remote host for information about the state of the NFS server on that machine:
$ showmount -a
Output:
All mount points on nfs-server: nfs-server:/olddisk nfs-server:/sales nfs-server:/data nfs-server:/mp3s-video nfs-server:/wwwroot
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 2 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
In the file exports, the option ‘rsync’ is not correct. It should be ‘sync’ or ‘async’.
See: man exports
Also check out the difference between no_subtree_check and subtree_check while you’re reading.
I have tried command
$ sudo apt-get install nfs-kernel-server portmap nfs-common
But Following error msg is coming please give me solution..
Cannot register service: RPC: Authentication error; why = Client credential too weak
unable to register (STRINGPROGRAM, STRINGPROGRAMVERSION, udp).mmm@ubuntu:~$