Summary
This is a quick tutorial that guides you to create NFS server and mount it on your client.
Install required package
- If you are using OEL7, then you don’t have to install packages, since they are installed by default.
- If not, you are required to install portmap and nfs-utils.
You can use rpm -qa | grep portmap
to see if portmap is installed, also apt --installed list
can be used for whom use APT.
For those who didn’t install required packages, you can download required rpm package mentioned above and run following command rpm -ivh <RPM_PACKAGE>.rpm
to install.
If you cannot use RPM, you can also use YUM or APT to install these 2 packages by running sudo yum install <YUM_PACKAGE>
or sudo apt install <APT_PACKAGE>
.
/etc/exports
Edit your /etc/exports
to create rules for NFS.
Following is the format of /etc/exports
.
<DIR_TO_USED_FOR_NFS> <CLIENT_IP_ADDRESS>/<MASK>(<LIST_OF_RIGHTS>)
Attention, there’s no space betwwen <MASK>
and (<LIST_OF_RIGHTS>)
.
<DIR_TO_USED_FOR_NFS>
: The directory that you want to share.<CLIENT_IP_ADDRESS>
: Client IP address that will be allowed to connect.<MASK>
: Network mask.<LIST_OF_RIGHTS>
: Rights for clients, separates by comma.
<LIST_OF_RIGHTS>
can be the following options
- ro
: Read only,
- rw
: Read and write.
- all_squash
: All remote users will be marked as anonymous.
- root_squash
: Root remote users will be marked as anonymous. (This is recommended)
- no_all_squash
: Negation of all_squash
.
- no_root_squash
: Negation of root_squash
. (This is NOT recommended).
- sync
: Sync changes.
- etc.
Start NFS server
- If you are using OEL7, NFS server is started by default.
Use following command as root user to start NFS.
# service portmap start
# service nfs start
Be aware that you have to run commands above accordingly.
Also you can set to start NFS on start up by running following commands as root user.
# chkconfig --list portmap
# chkconfig --list nfs
Refresh export settings
exportfs -[aruv]
can be used to refresh /etc/exports
settings.
FYI exportfs
located in /sbin
.
Options:
- exportfs -a
: Mount all settings in /etc/exports
.
- exportfs -r
: Refresh /etc/exports
and update /etc/exports
and var/lib/nfs/xtab
.
- exportfs -u <DIR>
: Unmount desinated directory.
- exportfs -v
: Display shared directories.
Mount on clients
Example
Share /nfsserver
to 192.168.0.0/24 with read and write rights, regards all root users as anonymous user.
- Edit
/etc/exports
/nfsserver 192.168.0.0/24(rw,root_squash,sync)
- Refresh after editing
/etc/exports
.
# /sbin/exportfs -a
- Make directory on client.
# mkdir /nfsshare
- Mount NFS to
/nfsshare
mount <NFS_SERVER_IP_ADDRESS>:/nfsserver /nfsshare