About Network File System (NFS)
NFS, Network File System, is used for share files between linux/unix to unix/linux systems. With NFS, users can access files on remote systems as if they were stored locally.
NFS has many practical uses. Some of the more common uses include:
- Data that would otherwise be duplicated on each client can be kept in a single location and accessed by clients on the network.
- Several clients may need access to the
/usr/ports/distfiles
directory. Sharing that directory allows for quick access to the source files without having to download them to each client.
- On large networks, it is often more convenient to configure a central NFS server on which all user home directories are stored. Users can log into a client anywhere on the network and have access to their home directories.
- Administration of NFS exports is simplified. For example, there is only one file system where security or backup policies must be set.
- Removable media storage devices can be used by other machines on the network. This reduces the number of devices throughout the network and provides a centralized location to manage their security. It is often more convenient to install software on multiple machines from a centralized installation media.
NFS consists of a server and one or more clients. The client remotely accesses the data that is stored on the server machine. In order for this to function properly, a few processes have to be configured and running.
These daemons must be running on the server:
- nfsd – The NFS daemon which services requests from NFS clients.
- mountd – The NFS mount daemon which carries out requests received from nfsd.
- rpcbind – This daemon allows NFS clients to discover which port the NFS server is using.
Setup NFS Server On openSUSE 42.1
This tutorial will describe how to setup NFS server on openSUSE 42.1. The steps given in this tutorial should work on older openSUSE versions such as 13.2, 13.1 etc.
Scenario
For the purpose of this guide, I will be using two systems. The NFS server is openSUSE 42.1 and NFS client is Ubuntu 14.04 LTS.
Here is the ip address details of my server and client systems.
- NFS Server IP Address : 192.168.1.102/24
- NFS Client IP Address : 192.168.1.100/24
Install NFS in Server system
sudo zypper in nfs-kernel-server
Start NFS service
Enable and Start rpcbind and nfs services.
sudo systemctl enable rpcbind.service
sudo systemctl start rpcbind.service
sudo systemctl enable nfsserver.service
sudo systemctl start nfsserver.service
Install NFS in Client System
Enter the following command in client to install nfs-client package.
On Debian/Ubuntu:
sudo apt-get install nfs-common
On RHEL/CentOS/:
sudo yum install nfs-utils nfs-utils-lib
On SUSE/openSUSE:
sudo zypper in nfs-client
Create NFS shares in server
Create a shared directory named ‘/var/unixmen_share’ in server and let the client users to read and write files in that directory.
sudo mkdir /var/unixmen_share
sudo chmod 755 /var/unixmen_share/
Export shared directory on NFS Server
Open /etc/exports file,
sudo nano /etc/exports
Add the nfs share in it.
# See the exports(5) manpage for a description of the syntax of this file. # This file contains a list of all directories that are to be exported to # other computers via NFS (Network File System). # This file used by rpc.nfsd and rpc.mountd. See their manpages for details # on how make changes in this file effective. /var/unixmen_share/ 192.168.1.0/24(rw,sync,no_root_squash,no_all_squash)
Save and close the file.
where,
- /var/unixmen_share – shared directory
- 192.168.1.0/24 – IP address range of clients
- rw – Read/Write permission to shared folder
- sync – Synchronize shared directory
- no_root_squash – Enable root privilege
- no_all_squash – Enable user’s authority
Please be mindful that if you modify the /etc/exports file in future, you should run the following command to enable the changes.
sudo exportfs -a
Now restart rpcbind and nfs services.
sudo systemctl restart rpcbind.service
sudo systemctl restart nfsserver.service
Mount NFS shares in client
Go to your client system and Create a mount point to mount the share directory ‘var/unixmen_local’ which we created earlier.
sudo mkdir /var/nfs_share
By default, openSUSE firewall doesn’t allow remote clients to connect to NFS server.
To allow NFS server to access from the outbound, goto YAST control center -> Security and Users -> Firewall. Navigate to Allowed Services tab. Select NFS Secure Service from Service to Allow drop down box and click add. Finally click Next to allow the nfs service through suse firewall.
Then mount the nfs share in the client system using the following command:
sudo mount -t nfs 192.168.1.102:/var/unixmen_share/ /var/nfs_share/
Now the NFS share will be mounted on client systems without any issues.
Verify NFS
Verify the server NFS share is mounted in client using following methods.
sudo df -h
Sample output:
Filesystem Size Used Avail Use% Mounted on /dev/mapper/lubuntu--vg-root 455G 331G 101G 77% / none 4.0K 0 4.0K 0% /sys/fs/cgroup udev 1.9G 4.0K 1.9G 1% /dev tmpfs 387M 1.3M 385M 1% /run none 5.0M 0 5.0M 0% /run/lock none 1.9G 45M 1.9G 3% /run/shm none 100M 24K 100M 1% /run/user /dev/sda1 236M 51M 173M 23% /boot 192.168.1.102:/var/unixmen_share/ 20G 14G 5.4G 72% /var/nfs_share
Alternatively, you can check the NFS shares using mount command.
sudo mount
Sample output:
/dev/mapper/lubuntu--vg-root on / type ext4 (rw,errors=remount-ro) proc on /proc type proc (rw,noexec,nosuid,nodev) sysfs on /sys type sysfs (rw,noexec,nosuid,nodev) none on /sys/fs/cgroup type tmpfs (rw) none on /sys/fs/fuse/connections type fusectl (rw) none on /sys/kernel/debug type debugfs (rw) none on /sys/kernel/security type securityfs (rw) udev on /dev type devtmpfs (rw,mode=0755) devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620) tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755) none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880) none on /run/shm type tmpfs (rw,nosuid,nodev) none on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755) none on /sys/fs/pstore type pstore (rw) /dev/sda1 on /boot type ext2 (rw) binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev) systemd on /sys/fs/cgroup/systemd type cgroup (rw,noexec,nosuid,nodev,none,name=systemd) gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,user=sk) rpc_pipefs on /run/rpc_pipefs type rpc_pipefs (rw) 192.168.1.102:/var/unixmen_share/ on /var/nfs_share type nfs (rw,vers=4,addr=192.168.1.102,clientaddr=192.168.1.100)
Automount the NFS Shares
To mount the shares automatically instead of mounting them manually at every reboot, add the following lines shown in bold in the ‘/etc/fstab’ file of client system.
Edit file /etc/fstab,
sudo nano vi /etc/fstab
Add the following line in it.
192.168.1.102:/var/unixmen_share/ /var/nfs_share/ nfs rw,sync,hard,intr 0 0
Reboot the client system and check the share. You should see the shares are automatically mounted.
sudo mount
Sample output:
/dev/mapper/lubuntu--vg-root on / type ext4 (rw,errors=remount-ro) proc on /proc type proc (rw,noexec,nosuid,nodev) sysfs on /sys type sysfs (rw,noexec,nosuid,nodev) none on /sys/fs/cgroup type tmpfs (rw) none on /sys/fs/fuse/connections type fusectl (rw) none on /sys/kernel/debug type debugfs (rw) none on /sys/kernel/security type securityfs (rw) udev on /dev type devtmpfs (rw,mode=0755) devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620) tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755) none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880) none on /run/shm type tmpfs (rw,nosuid,nodev) none on /run/user type tmpfs (rw,noexec,nosuid,nodev,size=104857600,mode=0755) none on /sys/fs/pstore type pstore (rw) /dev/sda1 on /boot type ext2 (rw) binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev) systemd on /sys/fs/cgroup/systemd type cgroup (rw,noexec,nosuid,nodev,none,name=systemd) gvfsd-fuse on /run/user/1000/gvfs type fuse.gvfsd-fuse (rw,nosuid,nodev,user=sk) rpc_pipefs on /run/rpc_pipefs type rpc_pipefs (rw) 192.168.1.102:/var/unixmen_share/ on /var/nfs_share type nfs (rw,vers=4,addr=192.168.1.102,clientaddr=192.168.1.100)
That’s it. Now NFS server is ready to use.
Good luck!