Hi team,
I'm quite new
with Fedora, and I've digging a lot to make NFS work. As it is a quite
straightforward procedure, most guides I've found are quite outdated.Installation By default NFS is already included in most fedora installations. To verify NFS is installed, type the following command: $ rpm -q nfs-utils this should output something like: nfs-utils-2.2.1-3.rc2.fc26.x86_64 If not, then install the NFS packages by typing: $ sudo dnf install -y nfs-utils system-config-nfs Configuring NFS There are three main configuration files you will need to edit to set up an NFS server: /etc/exports, /etc/hosts.allow, and /etc/hosts.deny. The only file used in this section of the chapter is /etc/exports to get NFS up and running. /etc/exports, Main configuration file /etc/hosts.allow, Hosts to allow access /etc/hosts.deny, Hosts to deny access NFS is not enabled by default on all Fedora spins. To activate NFS type the following commands: $ sudo systemctl enable rpcbind $ sudo systemctl enable nfs-server $ sudo systemctl start rpcbind $ sudo systemctl start nfs-server $ sudo systemctl start rpc-statd $ sudo systemctl start nfs-idmapd You can check that all services are active typing the following commands: $ sudo systemctl status rpcbind Expected output: "Active: active (running)" $ sudo systemctl status rpc-statd Expected output: "Active: active (running)" $ sudo systemctl status nfs-server Expected output: "Active: active (exited)" $ sudo systemctl status nfs-idmapd Expected output: "Active: active (running)" Configure Firewall We need to configure firewall on NFS server to allow client servers to access NFS shares. To do that, run the following commands on the NFS server. $ firewall-cmd --permanent --zone public --add-service rpc-bind $ firewall-cmd --permanent --zone public --add-service nfs $ firewall-cmd --reload Creating Shares By default NFS does not share out any folders or drive volumes. To create the first share, open a shell prompt, and enter the following command to begin editing the /etc/exports file: $ sudo vi /etc/exports The vi editor window will open to what looks like a new file. This is because the /etc/exports file has no existing configuration settings at install. The format that will be used to share folders and drive volumes is straightforward: directory hosts(options) Here is a break down of the 2 lines listed: directory, This is the directory or volume to be shared hosts, This is a client computer that will have access to the share. The preferred way to list the host is by IP Address, but DNS names can be used. A group of hosts can be configured by entering an IP range such as: /var/ftp/pub 192.168.1.0/255.255.255.0(ro) "/home/user/my files" 192.168.1.0/24(rw) options - The options specify the kind of access mentioned hosts will have to the shared directory. Here are some of the most common options: ro, read only access is granted to the Directory rw, read and write access is granted to the Directory no_root_squash, by default, access by a remote root users is treated as the user 'nobody'. To allow the same access to a remote 'root' account as the local root user, add this option. Stop (medium size).png Allowing remote root access through NFS is a major security risk. Avoid using this option unless necessary! no_subtree_check, subtree checking verifies the a file being accessed is in a sub folder on the same volume. When sharing an entire drive volume, this option will speed up access to the sub-folders and files. sync, By default NFS uses 'sync' transfers, so the NFS server must send an acknowledgment that the file has been written. Using the async option will speed up file transfers by disabling the acknowledgment. To share the /var/ftp/pub folder with read only access, and with sync/no_subtree_check allowed, edit the /etc/exports file as below: /var/ftp/pub 192.168.54.0/255.255.255.0(ro,sync,no_subtree_check) Using the * in the Hosts field makes the share accessible to everyone Select the Basic Permisions by clicking the [Read-only] or [Read/Write] radio buttons. On the General Options tab, select the [Disable subtree checking] and the [Sync write operations on request] radio buttons. Click the [OK] button to save your changes. In a shell prompt, enter the following command to edit the /etc/exports file and verify the changes just made: $ sudo vi /etc/exports The following example should be displayed in the vi editor window: /var/ftp/pub 192.168.54.0/255.255.255.0(ro,sync,no_wdelay,no_subtree_check,nohide) Exit the vi editor, and restart the NFS service to apply the changes by typing (Fedora 17): $ exportfs -r Extras: $ exportfs -v : Displays a list of shares files and export options on a server $ exportfs -a : Exports all directories listed in /etc/exports $ exportfs -u : Unexport one or more directories $ exportfs -r : Reexport all directories after modifying /etc/exports After configuring NFS server, we need to mount that shared directory in the client-server. NFS Clients Before mounting the NFS share, we need to check the available shares on the NFS server. To do that, run the following command on the client-server. $ showmount -e 192.168.12.5 Export list for 192.168.12.5: /nfsfileshare 192.168.12.7 As per the command, the /nfsfileshare is available on 192.168.12.5. Extras: $ showmount -e : Shows the available shares on your local machine (NFS Server). $ showmount -e <server-ip or hostname>: Lists the available shares on the remote server Now, create a mount point to mount the shared folder ‘/nfsfileshare’ which we’ve created before in the server. $ mkdir /mnt/nfsfileshare Use below command to mount a shared directory “/nfsfileshare” from NFS server “192.168.12.5” in “/mnt/nfsfileshare” on client-server. $ mount 192.168.12.5:/nfsfileshare /mnt/nfsfileshare Verify the mounted share on client server using “mount” command. [root@client ~]$ mount | grep nfs sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime) nfsd on /proc/fs/nfsd type nfsd (rw,relatime) 192.168.12.5:/nfsfileshare on /mnt/nfsfileshare type nfs4 (rw,relatime,vers=4.1,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.12.7,local_lock=none,addr=192.168.12.5) Also, you can use “df” command to check the mounted NFS share. $ df -hT Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 478M 0 478M 0% /dev tmpfs tmpfs 489M 0 489M 0% /dev/shm tmpfs tmpfs 489M 620K 488M 1% /run tmpfs tmpfs 489M 0 489M 0% /sys/fs/cgroup /dev/mapper/fedora-root xfs 18G 1.3G 17G 8% / tmpfs tmpfs 489M 4.0K 489M 1% /tmp /dev/sda1 ext4 477M 93M 355M 21% /boot tmpfs tmpfs 98M 0 98M 0% /run/user/0 192.168.12.5:/nfsfileshare nfs4 50G 858M 50G 2% /mnt/nfsfileshare Create a test file on the mounted directory to verify the read and write access on NFS share. $ touch /mnt/nfsfileshare/test If the above command returns no error, you have working NFS setup. ... server:/var/ftp/pub /media/nfs nfs rw 0 0 Automount NFS Shares To mount the shares automatically on every reboot, need to modify “/etc/fstab” file of your client system. Add “green” line at the end. $ sudo vi /etc/fstab # # /etc/fstab # Created by anaconda on Tue May 26 21:30:49 2015 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/fedora-root / xfs defaults 0 0 UUID=f748af6c-0de9-4dc0-98e6-959ffc400f2f /boot ext4 defaults 1 2 /dev/mapper/fedora-swap swap swap defaults 0 0 192.168.12.5:/nfsfileshare/ /mnt/nfsfileshare nfs rw,sync,hard,intr 0 0 save and close the file. Reboot the client machine and check the share whether it is automatically mounted or not. $ sudo reboot Verify the mounted share on client server using “mount” command. $ mount | grep nfs sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw,relatime) nfsd on /proc/fs/nfsd type nfsd (rw,relatime) 192.168.12.5:/nfsfileshare on /mnt/nfsfileshare type nfs4 (rw,relatime,sync,vers=4.1,rsize=262144,wsize=262144,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.12.7,local_lock=none,addr=192.168.12.5) If you want to unmount that shared directory from your client server after you are done with the file sharing, you can unmount that particular directory using“umount” command. $ umount /mnt/nfsfileshare All credits to Raj https://www.itzgeek.com/how-tos/linux/centos-how-tos/how-to-setup-nfs-server-on-centos-7-rhel-7-fedora-22.html
_______________________________________________ docs mailing list -- docs@xxxxxxxxxxxxxxxxxxxxxxx To unsubscribe send an email to docs-leave@xxxxxxxxxxxxxxxxxxxxxxx